Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions evaluate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn argument_name_value(s: &str, delim: char) -> Option<(&str, &str)> {
}
}

fn build_variables(arguments: &getopts::Matches, context: &mut Context<'_>) {
fn build_variables(arguments: &getopts::Matches, context: &mut Context<'_, '_>) {
for boolean in arguments.opt_strs("boolean") {
match argument_name_value(&boolean, '=') {
Some((name, "true")) => context.set_variable(name, true),
Expand Down Expand Up @@ -80,7 +80,7 @@ fn build_variables(arguments: &getopts::Matches, context: &mut Context<'_>) {
}
}

fn build_namespaces(arguments: &getopts::Matches, context: &mut Context<'_>) {
fn build_namespaces(arguments: &getopts::Matches, context: &mut Context<'_, '_>) {
for ns_defn in arguments.opt_strs("namespace") {
match argument_name_value(&ns_defn, ':') {
Some((prefix, uri)) => context.set_namespace(prefix, uri),
Expand Down
20 changes: 10 additions & 10 deletions src/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub enum PrincipalNodeType {
pub trait AxisLike: fmt::Debug {
/// Applies the given node test to the nodes selected by this axis,
/// adding matching nodes to the nodeset.
fn select_nodes<'c, 'd>(
fn select_nodes<'c, 'd, 'f>(
&self,
context: &context::Evaluation<'c, 'd>,
context: &context::Evaluation<'c, 'd, 'f>,
node_test: &dyn NodeTest,
) -> OrderedNodes<'d>;

Expand Down Expand Up @@ -45,14 +45,14 @@ pub enum Axis {
SelfAxis,
}

struct CompleteNodeTest<'c, 'd> {
context: &'c context::Evaluation<'c, 'd>,
struct CompleteNodeTest<'c, 'd, 'f> {
context: &'c context::Evaluation<'c, 'd, 'f>,
node_test: &'c dyn NodeTest,
result: OrderedNodes<'d>,
}

impl<'c, 'd> CompleteNodeTest<'c, 'd> {
fn new(context: &'c context::Evaluation<'c, 'd>, node_test: &'c dyn NodeTest) -> Self {
impl<'c, 'd, 'f> CompleteNodeTest<'c, 'd, 'f> {
fn new(context: &'c context::Evaluation<'c, 'd, 'f>, node_test: &'c dyn NodeTest) -> Self {
CompleteNodeTest {
context,
node_test,
Expand All @@ -67,9 +67,9 @@ impl<'c, 'd> CompleteNodeTest<'c, 'd> {
}

impl AxisLike for Axis {
fn select_nodes<'c, 'd>(
fn select_nodes<'c, 'd, 'f>(
&self,
context: &context::Evaluation<'c, 'd>,
context: &context::Evaluation<'c, 'd, 'f>,
node_test: &dyn NodeTest,
) -> OrderedNodes<'d> {
use self::Axis::*;
Expand Down Expand Up @@ -220,9 +220,9 @@ mod test {
#[derive(Debug)]
struct DummyNodeTest;
impl NodeTest for DummyNodeTest {
fn test<'c, 'd>(
fn test<'c, 'd, 'f>(
&self,
context: &context::Evaluation<'c, 'd>,
context: &context::Evaluation<'c, 'd, 'f>,
result: &mut OrderedNodes<'d>,
) {
result.add(context.node)
Expand Down
38 changes: 19 additions & 19 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::nodeset::{Node, OrderedNodes};
use crate::{OwnedQName, Value};

/// A mapping of names to XPath functions.
type Functions = HashMap<OwnedQName, Box<dyn function::Function + 'static>>;
type Functions<'f> = HashMap<OwnedQName, Box<dyn function::Function + 'f>>;
/// A mapping of names to XPath variables.
type Variables<'d> = HashMap<OwnedQName, Value<'d>>;
/// A mapping of namespace prefixes to namespace URIs.
Expand All @@ -32,8 +32,8 @@ type Namespaces = HashMap<String, String>;
///
/// struct Sigmoid;
/// impl function::Function for Sigmoid {
/// fn evaluate<'c, 'd>(&self,
/// _context: &context::Evaluation<'c, 'd>,
/// fn evaluate<'c, 'd, 'f>(&self,
/// _context: &context::Evaluation<'c, 'd, 'f>,
/// args: Vec<Value<'d>>)
/// -> Result<Value<'d>, function::Error>
/// {
Expand Down Expand Up @@ -72,13 +72,13 @@ type Namespaces = HashMap<String, String>;
/// the `evaluate` method and is not the root of the tree but the
/// top-most element.
///
pub struct Context<'d> {
functions: Functions,
pub struct Context<'d, 'f> {
functions: Functions<'f>,
variables: Variables<'d>,
namespaces: Namespaces,
}

impl<'d> Context<'d> {
impl<'d, 'f> Context<'d, 'f> {
/// Registers the core XPath 1.0 functions.
pub fn new() -> Self {
let mut context = Self::without_core_functions();
Expand All @@ -99,7 +99,7 @@ impl<'d> Context<'d> {
pub fn set_function<N, F>(&mut self, name: N, function: F)
where
N: Into<OwnedQName>,
F: function::Function + 'static,
F: function::Function + 'f,
{
self.functions.insert(name.into(), Box::new(function));
}
Expand All @@ -119,7 +119,7 @@ impl<'d> Context<'d> {
}
}

impl<'d> Default for Context<'d> {
impl<'d, 'f> Default for Context<'d, 'f> {
fn default() -> Self {
Context::new()
}
Expand All @@ -136,21 +136,21 @@ impl<'d> Default for Context<'d> {
/// (`'c`) and that of the document (`'d`). This allows the
/// user-provided context to live shorter than the document.
#[derive(Copy, Clone)]
pub struct Evaluation<'c, 'd> {
pub struct Evaluation<'c, 'd, 'f> {
/// The context node
pub node: Node<'d>,
/// The context position
pub position: usize,
/// The context size
pub size: usize,
functions: &'c Functions,
functions: &'c Functions<'f>,
variables: &'c Variables<'d>,
namespaces: &'c Namespaces,
}

impl<'c, 'd> Evaluation<'c, 'd> {
impl<'c, 'd, 'f> Evaluation<'c, 'd, 'f> {
/// Prepares the context used while evaluating the XPath expression
pub fn new(context: &'c Context<'d>, node: Node<'d>) -> Evaluation<'c, 'd> {
pub fn new(context: &'c Context<'d, 'f>, node: Node<'d>) -> Evaluation<'c, 'd, 'f> {
Evaluation {
node,
functions: &context.functions,
Expand All @@ -162,7 +162,7 @@ impl<'c, 'd> Evaluation<'c, 'd> {
}

/// Creates a new context node using the provided node
pub fn new_context_for<N>(&self, node: N) -> Evaluation<'c, 'd>
pub fn new_context_for<N>(&self, node: N) -> Evaluation<'c, 'd, 'f>
where
N: Into<Node<'d>>,
{
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<'c, 'd> Evaluation<'c, 'd> {
}

/// Yields a new `Evaluation` context for each node in the nodeset.
pub fn new_contexts_for(self, nodes: OrderedNodes<'d>) -> EvaluationNodesetIter<'c, 'd> {
pub fn new_contexts_for(self, nodes: OrderedNodes<'d>) -> EvaluationNodesetIter<'c, 'd, 'f> {
let sz = nodes.size();
EvaluationNodesetIter {
parent: self,
Expand All @@ -203,16 +203,16 @@ impl<'c, 'd> Evaluation<'c, 'd> {
}

/// An iterator for the contexts of each node in a nodeset
pub struct EvaluationNodesetIter<'c, 'd> {
parent: Evaluation<'c, 'd>,
pub struct EvaluationNodesetIter<'c, 'd, 'f> {
parent: Evaluation<'c, 'd, 'f>,
nodes: iter::Enumerate<::std::vec::IntoIter<Node<'d>>>,
size: usize,
}

impl<'c, 'd> Iterator for EvaluationNodesetIter<'c, 'd> {
type Item = Evaluation<'c, 'd>;
impl<'c, 'd, 'f> Iterator for EvaluationNodesetIter<'c, 'd, 'f> {
type Item = Evaluation<'c, 'd, 'f>;

fn next(&mut self) -> Option<Evaluation<'c, 'd>> {
fn next(&mut self) -> Option<Evaluation<'c, 'd, 'f>> {
self.nodes.next().map(|(idx, node)| Evaluation {
node,
position: idx + 1,
Expand Down
Loading