Struct fgen::Context [−][src]
pub struct Context { /* fields omitted */ }
The struct that holds the context of a template rendering.
Light wrapper around a BTreeMap
for easier insertions of Serializable
values
Methods
impl Context
[src]
impl Context
pub fn new() -> Context
[src]
pub fn new() -> Context
Initializes an empty context
pub fn add<T>(&mut self, key: &str, val: &T) where
T: Serialize + ?Sized,
[src]
pub fn add<T>(&mut self, key: &str, val: &T) where
T: Serialize + ?Sized,
Converts the val
parameter to Value
and insert it into the context
ⓘThis example is not tested
let mut context = Context::new(); // user is an instance of a struct implementing `Serialize` context.add("number_users", 42);
pub fn insert<T>(&mut self, key: &str, val: &T) where
T: Serialize + ?Sized,
[src]
pub fn insert<T>(&mut self, key: &str, val: &T) where
T: Serialize + ?Sized,
Converts the val
parameter to Value
and insert it into the context
ⓘThis example is not tested
let mut context = Context::new(); // user is an instance of a struct implementing `Serialize` context.insert("number_users", 42);
pub fn extend(&mut self, source: Context)
[src]
pub fn extend(&mut self, source: Context)
Appends the data of the source
parameter to self
, overwriting existing keys.
The source context will be dropped.
ⓘThis example is not tested
let mut target = Context::new(); target.add("a", 1); target.add("b", 2); let mut source = Context::new(); source.add("b", 3); source.add("d", 4); target.extend(source);
Trait Implementations
impl Clone for Context
[src]
impl Clone for Context
fn clone(&self) -> Context
[src]
fn clone(&self) -> Context
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl Default for Context
[src]
impl Default for Context
impl Debug for Context
[src]
impl Debug for Context
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl PartialEq<Context> for Context
[src]
impl PartialEq<Context> for Context
fn eq(&self, other: &Context) -> bool
[src]
fn eq(&self, other: &Context) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Context) -> bool
[src]
fn ne(&self, other: &Context) -> bool
This method tests for !=
.
impl Serialize for Context
[src]
impl Serialize for Context
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
[src]
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more