pub struct StaticContextBuilder<F: FnMut(&str) -> Result<(), Error>>(/* private fields */);
Expand description

Builder for a StaticContext. The main feature of the static context is the ability to set up a callback for messages.

use std::rc::Rc;
use xrust::qname::QualifiedName;
use xrust::value::Value;
use xrust::item::{Item, Sequence, SequenceTrait, NodeType};
use xrust::trees::intmuttree::NodeBuilder;
use xrust::transform::Transform;
use xrust::transform::context::{Context, ContextBuilder, StaticContext, StaticContextBuilder};

let mut message = String::from("no message received");
let xform = Transform::LiteralElement(
  QualifiedName::new(None, None, String::from("Example")),
  Box::new(Transform::SequenceItems(vec![
Transform::Message(
	Box::new(Transform::Literal(Rc::new(Item::Value(Value::from("a message from the transformation"))))),
	None,
	Box::new(Transform::Empty),
	Box::new(Transform::Empty),
),
Transform::Literal(Rc::new(Item::Value(Value::from("element content")))),
  ]))
);
let mut context = ContextBuilder::new()
.result_document(NodeBuilder::new(NodeType::Document).build())
.build();
let mut static_context = StaticContextBuilder::new()
.message(|m| {message = String::from(m); Ok(())})
.build();
let sequence = context.dispatch(&mut static_context, &xform).expect("evaluation failed");

assert_eq!(sequence.to_xml(), "<Example>element content</Example>");
assert_eq!(message, "a message from the transformation")

Implementations§

source§

impl<F> StaticContextBuilder<F>
where F: FnMut(&str) -> Result<(), Error>,

source

pub fn new() -> Self

source

pub fn message(self, f: F) -> Self

source

pub fn build(self) -> StaticContext<F>

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for StaticContextBuilder<F>
where F: RefUnwindSafe,

§

impl<F> Send for StaticContextBuilder<F>
where F: Send,

§

impl<F> Sync for StaticContextBuilder<F>
where F: Sync,

§

impl<F> Unpin for StaticContextBuilder<F>
where F: Unpin,

§

impl<F> UnwindSafe for StaticContextBuilder<F>
where F: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.