Struct Value

pub struct Value { /* private fields */ }

The Value type that Tera uses internally and that will handle ser/de

Implementations

impl Value

fn none() -> Self
fn undefined() -> Self
fn kind(&self) -> ValueKind
fn is_undefined(&self) -> bool
fn is_none(&self) -> bool
fn is_bool(&self) -> bool
fn is_string(&self) -> bool
fn is_i128(&self) -> bool
fn is_u128(&self) -> bool
fn is_i64(&self) -> bool
fn is_u64(&self) -> bool
fn is_f64(&self) -> bool
fn is_array(&self) -> bool
fn is_map(&self) -> bool
fn is_bytes(&self) -> bool
fn from_serializable<T: Serialize + ?Sized>(value: &T) -> Value

Creates a Value from something that impl Serialize. Panics if serialization fails; see Self::try_from_serializable for the fallible variant.

fn try_from_serializable<T: Serialize + ?Sized>(value: &T) -> TeraResult<Value>

Fallible way to create a Value from something that impl Serialize

fn normal_string(val: &str) -> Value

Creates a normal string that will be escaped

fn safe_string(val: &str) -> Value

Creates a safe string that won't be escaped

fn bytes(bytes: impl Into<Vec<u8>>) -> Value

Creates a bytes Value

fn as_i128(&self) -> Option<i128>

If the Value is an integer that can fit in a i128, return that otherwise None.

fn as_u128(&self) -> Option<u128>

If the Value is an integer that can fit in a u128, return that otherwise None.

fn as_i64(&self) -> Option<i64>

If the Value is an integer that can fit in an i64, return that otherwise None.

fn as_u64(&self) -> Option<u64>

If the Value is an integer that can fit in a u64, return that otherwise None.

fn as_f64(&self) -> Option<f64>

If the Value is a f64 return the associated f64, otherwise None.

fn as_number(&self) -> Option<Number>

Returns None for non-numeric values and for u128 values exceeding i128::MAX, since Number::Integer only carries i128. i128 ought to be enough for everyone.

fn is_number(&self) -> bool

Returns true if the value is an integer or a float

fn as_str(&self) -> Option<&str>

If the Value is a string return the associated str, otherwise None.

fn as_bool(&self) -> Option<bool>

If the Value is a bool return the associated bool, otherwise None.

fn is_safe(&self) -> bool

Returns whether the value is safe (i.e. does not need escaping). Non-safe strings and arrays/maps/bytes return false; safe strings and all other scalar kinds return true.

fn mark_safe(self) -> Self

Consumes the Value, marking it as a safe string if it is one.

fn as_map(&self) -> Option<&Map>

If the Value is a map return the associated Map, otherwise None.

fn as_array(&self) -> Option<&[Value]>

If the Value is an array return the associated slice, otherwise None.

fn as_bytes(&self) -> Option<&[u8]>

If the Value is a Bytes return the associated bytes, otherwise None.

fn into_map(self) -> Option<Map>

Consumes the current Value to return its inner Map if it is one, otherwise None.

fn get_from_path<'s>(&'s self, path: &'s str) -> Option<&'s Value>

Returns a reference to the Value at the given path or None if there's nothing there

fn is_truthy(&self) -> bool

Returns the truthiness of a value, eg not empty map/arrays/string and numbers different from 0

fn len(&self) -> Option<usize>

Returns the length of the value. Only works with maps, arrays, bytes and strings. For strings, if you use the unicode feature it will return the number of graphemes otherwise the number of chars.

fn reverse(&self) -> TeraResult<Value>

Reverses the content: only works for arrays, bytes and strings

fn name(&self) -> &'static str

Returns a string name for the current enum member. Used in error messages

Trait Implementations

impl Clone for Value

fn clone(&self) -> Value

impl Debug for Value

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Display for Value

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Eq for Value

impl From<&[Value]> for Value

fn from(value: &[Value]) -> Self

impl From<&[u8]> for Value

fn from(value: &[u8]) -> Self

impl From<&str> for Value

fn from(value: &str) -> Self

impl From<()> for Value

fn from(()) -> Self

impl From<Cow<'_, str>> for Value

fn from(value: Cow<'_, str>) -> Self

impl From<Key<'static>> for Value

fn from(value: Key<'static>) -> Self

impl From<Number> for Value

fn from(n: Number) -> Self

impl From<String> for Value

fn from(value: String) -> Self

impl From<bool> for Value

fn from(value: bool) -> Self

impl From<char> for Value

fn from(value: char) -> Self

impl From<f32> for Value

fn from(value: f32) -> Self

impl From<f64> for Value

fn from(value: f64) -> Self

impl From<i128> for Value

fn from(value: i128) -> Self

impl From<i16> for Value

fn from(value: i16) -> Self

impl From<i32> for Value

fn from(value: i32) -> Self

impl From<i64> for Value

fn from(value: i64) -> Self

impl From<i8> for Value

fn from(value: i8) -> Self

impl From<isize> for Value

fn from(value: isize) -> Self

impl From<u128> for Value

fn from(value: u128) -> Self

impl From<u16> for Value

fn from(value: u16) -> Self

impl From<u32> for Value

fn from(value: u32) -> Self

impl From<u64> for Value

fn from(value: u64) -> Self

impl From<u8> for Value

fn from(value: u8) -> Self

impl From<usize> for Value

fn from(value: usize) -> Self

impl Ord for Value

fn cmp(&self, other: &Self) -> Ordering

impl PartialEq for Value

fn eq(&self, other: &Self) -> bool

impl PartialOrd for Value

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

impl Serialize for Value

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
    S: Serializer,

impl<'de> Deserializer<'de> for Value

type Error = DeserializationFailed;
fn deserialize_any<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_option<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_newtype_struct<V: Visitor<'de>>(self, name: &'static str, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_enum<V: Visitor<'de>>(self, name: &'static str, variants: &'static [&'static str], visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_unit_struct<V>(self, name: &'static str, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_tuple_struct<V>(self, name: &'static str, len: usize, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_struct<V>(self, name: &'static str, fields: &'static [&'static str], visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where
    V: Visitor<'de>,

impl<'k> ArgFromValue<'k> for Value

type Output = Value;
fn from_value(value: &'k Value) -> TeraResult<Self::Output>

impl<K: Into<Key<'static>>, T: Into<Value>> From<BTreeMap<K, T>> for Value

fn from(input: BTreeMap<K, T>) -> Self

impl<K: Into<Key<'static>>, T: Into<Value>> From<HashMap<K, T>> for Value

fn from(input: HashMap<K, T>) -> Self

impl<T: Into<Value>> From<BTreeSet<T>> for Value

fn from(value: BTreeSet<T>) -> Self

impl<T: Into<Value>> From<Option<T>> for Value

fn from(value: Option<T>) -> Self

impl<T: Into<Value>> From<Vec<T>> for Value

fn from(value: Vec<T>) -> Self

Auto Trait Implementations

impl Freeze for Value

impl RefUnwindSafe for Value

impl Send for Value

impl Sync for Value

impl Unpin for Value

impl UnsafeUnpin for Value

impl UnwindSafe for Value

Blanket Implementations

impl<I> FunctionResult for Value where I: Into<Value>,

fn into_result(self) -> TeraResult<Value>

impl<T> Any for Value where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Value where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Value where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Value where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Value

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Value where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for Value where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for Value where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Value where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for Value where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>