Trait trimmer::Variable
[−]
[src]
pub trait Variable<'render>: Debug { fn typename(&self) -> &'static str; fn attr<'x>(&'x self, _attr: &str) -> Result<Var<'x, 'render>, DataError>
where
'render: 'x, { ... } fn index<'x>(
&'x self,
_key: &(Variable<'render> + 'render)
) -> Result<Var<'x, 'render>, DataError>
where
'render: 'x, { ... } fn output(&self) -> Result<Output, DataError> { ... } fn as_str_key<'x>(&'x self) -> Result<&'x str, DataError> { ... } fn as_int_key(&self) -> Result<usize, DataError> { ... } fn as_bool(&self) -> Result<bool, DataError> { ... } fn as_number(&self) -> Result<Number, DataError> { ... } fn as_comparable(&self) -> Result<Comparable, DataError> { ... } fn iterate<'x>(
&'x self
) -> Result<Box<Iterator<Item = Var<'x, 'render>> + 'x>, DataError>
where
'render: 'x, { ... } fn iterate_pairs<'x>(
&'x self
) -> Result<Box<Iterator<Item = (Var<'x, 'render>, Var<'x, 'render>)> + 'x>, DataError>
where
'render: 'x, { ... } }
A trait that you need to implement to put variable into the rendering context
Note: by default all operations return unsupported error
Required Methods
fn typename(&self) -> &'static str
Returns type name to use in error messages
Note this must return actual type of value from user point of view
not just rust type. For example for Json
type it should describe
Json::Object
as a mapping and Json::Array
as an array, not just
return Json
Provided Methods
fn attr<'x>(&'x self, _attr: &str) -> Result<Var<'x, 'render>, DataError> where
'render: 'x,
'render: 'x,
Evaluates a.b
operation
Depending on your domain a.x
may be equivalent of a["x"]
or
maybe not. Integer arguments a.0
are not supported.
fn index<'x>(
&'x self,
_key: &(Variable<'render> + 'render)
) -> Result<Var<'x, 'render>, DataError> where
'render: 'x,
&'x self,
_key: &(Variable<'render> + 'render)
) -> Result<Var<'x, 'render>, DataError> where
'render: 'x,
Evaluates a[b]
Depending on your domain a["x"]
may be equivalent of a.x
or
maybe not.
You may exract string value for a key with key.as_str_key()
and key.as_int_key()
.
Note that actual key may have a (rust) type that is different from type of self (i.e. may come from different library).
fn output(&self) -> Result<Output, DataError>
Evaluates {{ x }}
This operation may not be useful for array-, and mapping-like values
fn as_str_key<'x>(&'x self) -> Result<&'x str, DataError>
Return string value of the variable used as key in index
String keys are used for indexing dicts
It's okay not to implement this method for complex variables
fn as_int_key(&self) -> Result<usize, DataError>
Return intenger value of the variable used as key
Integer keys are used for indexing arrays
It's okay not to implement this method for complex variables
fn as_bool(&self) -> Result<bool, DataError>
Return boolean value of this object
This is used in conditions ## if x
fn as_number(&self) -> Result<Number, DataError>
Return value as it could be treated in numeric context
Numeric context is where +,-,*,/,%
operators are used. Use standard
into()
conversion to convert built-in value into internal
representation.
fn as_comparable(&self) -> Result<Comparable, DataError>
Return value of the object that might be compared to another value
Note we can only compare numbers with number and strings with
strings. All other types of comparisons are unsupported. Use standard
into()
conversion to convert built-in value into internal
representation.
fn iterate<'x>(
&'x self
) -> Result<Box<Iterator<Item = Var<'x, 'render>> + 'x>, DataError> where
'render: 'x,
&'x self
) -> Result<Box<Iterator<Item = Var<'x, 'render>> + 'x>, DataError> where
'render: 'x,
Return iterator over the value if appropriate
fn iterate_pairs<'x>(
&'x self
) -> Result<Box<Iterator<Item = (Var<'x, 'render>, Var<'x, 'render>)> + 'x>, DataError> where
'render: 'x,
&'x self
) -> Result<Box<Iterator<Item = (Var<'x, 'render>, Var<'x, 'render>)> + 'x>, DataError> where
'render: 'x,
Return iterator over pairs if appropriate
Implementors
impl<'a, 'render: 'a> Variable<'render> for &'a str
impl<'x> Variable<'x> for String
impl<'x> Variable<'x> for IpAddr
impl<'x> Variable<'x> for Ipv4Addr
impl<'x> Variable<'x> for Ipv6Addr
impl<'x> Variable<'x> for SocketAddr
impl<'x> Variable<'x> for Option<&'x str>
impl<'x> Variable<'x> for u8
impl<'x> Variable<'x> for i8
impl<'x> Variable<'x> for u16
impl<'x> Variable<'x> for i16
impl<'x> Variable<'x> for u32
impl<'x> Variable<'x> for i32
impl<'x> Variable<'x> for u64
impl<'x> Variable<'x> for i64
impl<'x> Variable<'x> for f32
impl<'x> Variable<'x> for f64
impl<'render, V> Variable<'render> for HashMap<String, V> where
V: Variable<'render> + 'render,impl<'a: 'render, 'render, V> Variable<'render> for HashMap<&'a str, V> where
V: Variable<'render> + 'render,impl<'a, 'render, T: Variable<'render> + 'render> Variable<'render> for Vec<T>
impl<'x> Variable<'x> for bool
impl<'render> Variable<'render> for Value