pub struct Value(_);
Expand description
Represents a dynamically typed value in the template engine.
Implementations
sourceimpl Value
impl Value
sourcepub fn from_serializable<T: Serialize>(value: &T) -> Value
pub fn from_serializable<T: Serialize>(value: &T) -> Value
Creates a value from something that can be serialized.
During serialization of the value, serializing_for_value
will return
true
which makes it possible to customize serialization for MiniJinja.
For more information see serializing_for_value
.
sourcepub fn from_safe_string(value: String) -> Value
pub fn from_safe_string(value: String) -> Value
Creates a value from a safe string.
sourcepub fn from_object<T: Object + 'static>(value: T) -> Value
pub fn from_object<T: Object + 'static>(value: T) -> Value
Creates a value from a dynamic object.
sourcepub fn downcast_object_ref<T: Object>(&self) -> Option<&T>
pub fn downcast_object_ref<T: Object>(&self) -> Option<&T>
Returns some reference to the boxed object if it is of type T
, or None if it isn’t.
This is basically the “reverse” of from_object
.
Example
use std::fmt;
#[derive(Debug)]
struct Thing {
id: usize,
}
impl fmt::Display for Thing {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
}
impl Object for Thing {}
let x_value = Value::from_object(Thing { id: 42 });
let thing = x_value.downcast_object_ref::<Thing>().unwrap();
assert_eq!(thing.id, 42);
sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Returns true
if this value is undefined.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialOrd<Value> for Value
impl PartialOrd<Value> for Value
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Value
Auto Trait Implementations
impl !RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl !UnwindSafe for Value
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more