Skip to main content

DynamicContext

Struct DynamicContext 

Source
pub struct DynamicContext<'a, N: DomNavigator> {
    pub static_context: &'a XPathContext<'a>,
    pub context_item: Option<XmlItem<N>>,
    pub context_position: usize,
    pub context_size: usize,
    pub current_datetime: Option<DateTimeValue>,
    pub implicit_timezone: Option<TimezoneOffset>,
    pub base_uri: Option<String>,
    pub variables: VarStore<XPathValue<N>>,
    /* private fields */
}
Expand description

XPath 2.0 dynamic context for expression evaluation.

The dynamic context provides runtime information:

  • Current context item (node or atomic value)
  • Context position and size (for predicates)
  • Variable bindings (indexed by VarSlotId)
  • Current date/time (stable for duration of query)
  • Implicit timezone

Fields§

§static_context: &'a XPathContext<'a>

Reference to the static context

§context_item: Option<XmlItem<N>>

Current context item (if any)

§context_position: usize

Current context position (1-based)

§context_size: usize

Current context size

§current_datetime: Option<DateTimeValue>

Current date/time (stable for entire query evaluation)

§implicit_timezone: Option<TimezoneOffset>

Implicit timezone

§base_uri: Option<String>

Base URI for resolving relative URIs

§variables: VarStore<XPathValue<N>>

Variable bindings (indexed by VarSlotId from NameBinder)

Implementations§

Source§

impl<'a, N: DomNavigator> DynamicContext<'a, N>

Source

pub fn new(static_context: &'a XPathContext<'a>, var_count: usize) -> Self

Create a new dynamic context with the given static context.

The var_count should be NameBinder::len() after binding.

Source

pub fn with_context_item(self, item: XmlItem<N>) -> Self

Set the context item.

Source

pub fn with_context_node(self, node: N) -> Self

Set the context node.

Source

pub fn with_position(self, position: usize, size: usize) -> Self

Set context position and size (for predicate evaluation).

Source

pub fn with_current_datetime(self, dt: DateTimeValue) -> Self

Set the current date/time.

Source

pub fn with_implicit_timezone(self, tz: TimezoneOffset) -> Self

Set the implicit timezone.

Source

pub fn require_context_item(&self) -> Result<&XmlItem<N>, XPathError>

Get the context item, returning an error if undefined.

Source

pub fn require_context_node(&self) -> Result<&N, XPathError>

Get the context node, returning an error if undefined or not a node.

Returns XPTY0020 if the context item is not a node (per XPath 2.0 spec for axis steps).

Source

pub fn get_variable(&self, slot: VarSlotId) -> Option<&XPathValue<N>>

Get a variable value by slot ID.

Source

pub fn set_variable(&mut self, slot: VarSlotId, value: XPathValue<N>)

Set a variable value.

Source

pub fn with_function_evaluator( self, evaluator: &'a dyn FunctionEvaluator<N>, ) -> Self

Set the function evaluator for custom function support.

Source

pub fn function_evaluator(&self) -> &dyn FunctionEvaluator<N>

Get the function evaluator, using built-in functions as default.

Returns a reference to the configured evaluator, or BuiltinEvaluator if none set.

Source

pub fn has_custom_evaluator(&self) -> bool

Check if a custom function evaluator is configured.

Source

pub fn eval_function( &mut self, handle: FunctionHandle, args: Vec<XPathValue<N>>, ) -> Result<XPathValue<N>, XPathError>

Evaluate a function using the configured evaluator.

This method exists to work around borrow checker issues with calling self.function_evaluator().eval(handle, self, args) where the evaluator borrow conflicts with the mutable self borrow.

Auto Trait Implementations§

§

impl<'a, N> !RefUnwindSafe for DynamicContext<'a, N>

§

impl<'a, N> !Send for DynamicContext<'a, N>

§

impl<'a, N> !Sync for DynamicContext<'a, N>

§

impl<'a, N> !UnwindSafe for DynamicContext<'a, N>

§

impl<'a, N> Freeze for DynamicContext<'a, N>
where N: Freeze,

§

impl<'a, N> Unpin for DynamicContext<'a, N>
where N: Unpin,

§

impl<'a, N> UnsafeUnpin for DynamicContext<'a, N>
where N: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSendSync for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.