pub struct Context { /* private fields */ }Expand description
Template data context wrapping JSON values.
Provides path resolution for template evaluation.
§Examples
use docx_templating::Context;
use serde_json::json;
// From JSON
let ctx = Context::from_json(json!({
"user": {
"name": "Ada Lovelace"
}
}));Implementations§
Source§impl Context
impl Context
Sourcepub fn from_serialize<T: Serialize + ?Sized>(value: &T) -> Result<Self>
pub fn from_serialize<T: Serialize + ?Sized>(value: &T) -> Result<Self>
Create context from any serializable type.
§Errors
Returns error if serialization to JSON fails.
§Examples
use docx_templating::Context;
use serde::Serialize;
#[derive(Serialize)]
struct User {
name: String,
age: u32,
}
let user = User { name: "Ada".into(), age: 36 };
let ctx = Context::from_serialize(&user).unwrap();Trait Implementations§
Source§impl IntoContext for Context
impl IntoContext for Context
Auto Trait Implementations§
impl Forget for Context
impl Freeze for Contextwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<Value>: Freeze,
*const LeafNode<String, Value> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, Value)>>: Freeze,
impl Move for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Contextwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Value>: UnsafeUnpin,
*const LeafNode<String, Value> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Value)>>: UnsafeUnpin,
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more