Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Number(i64),
    String(String),
    List(Vec<Value>),
    Map(HashMap<String, Value, BuildHasherDefault<FnvHasher>>),
}
Expand description

A polymorphic context value.

Templates can substitute Null, Bool, Number, and String variants directly via Display. List and Map are addressable through dot-notation paths (e.g. items.0 or user.name) and are typically consumed by control-flow blocks rather than direct substitution.

§Examples

use staticweaver_core::context::Value;

let v = Value::Number(42);
assert_eq!(v.to_string(), "42");

let nested = Value::Map({
    let mut m = std::collections::HashMap::new();
    let _ = m.insert("name".to_string(), Value::String("Alice".to_string()));
    m.into_iter().collect()
});
assert!(matches!(nested.get_path("name"), Some(Value::String(_))));

Variants§

§

Null

Absent / null. Renders as the empty string.

§

Bool(bool)

Boolean. Renders as "true" or "false".

§

Number(i64)

64-bit signed integer. Renders via Display.

§

String(String)

UTF-8 string. Renders verbatim (the engine handles HTML escaping).

§

List(Vec<Value>)

Ordered sequence of values. Addressable by 0, 1, …

§

Map(HashMap<String, Value, BuildHasherDefault<FnvHasher>>)

Nested map of named values. Addressable by key.

Implementations§

Source§

impl Value

Source

pub fn get_path(&self, path: &str) -> Option<&Value>

Walks a dot-separated path through nested Map and List variants, returning the final value if the entire path resolves.

List segments are matched as decimal indices (items.0.name). Returns None for any missing segment, type mismatch, or invalid index.

§Examples
use staticweaver_core::context::Value;
use fnv::FnvHashMap;

let mut inner = FnvHashMap::default();
let _ = inner.insert("name".to_string(), Value::String("Alice".to_string()));
let mut outer = FnvHashMap::default();
let _ = outer.insert("user".to_string(), Value::Map(inner));
let v = Value::Map(outer);

assert!(matches!(v.get_path("user.name"), Some(Value::String(_))));
assert!(v.get_path("user.missing").is_none());
Source

pub fn is_truthy(&self) -> bool

Returns true if the value is “truthy” — used by control-flow blocks ({{#if key}}).

Null and Bool(false) are falsy; Number(0) is falsy; empty String, List, and Map are falsy. Everything else is truthy.

§Examples
use staticweaver_core::context::Value;

assert!(!Value::Null.is_truthy());
assert!(!Value::Bool(false).is_truthy());
assert!(!Value::Number(0).is_truthy());
assert!(!Value::String(String::new()).is_truthy());
assert!(Value::String("x".to_string()).is_truthy());
assert!(Value::Number(1).is_truthy());
Source

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

Returns the inner string for Value::String, otherwise None. Convenience for the back-compat Context::get shape.

§Examples
use staticweaver_core::context::Value;

assert_eq!(Value::String("hi".to_string()).as_str(), Some("hi"));
assert_eq!(Value::Number(42).as_str(), None);

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Value

Source§

fn default() -> Value

Returns the “default value” for a type. Read more
Source§

impl Display for Value

Source§

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

Renders a primitive Value as its substitution string. List and Map render as the empty string — the engine treats them as non-substitutable and reports an error if they appear in a {{ }} tag rather than a control-flow block.

Source§

impl From<&str> for Value

Source§

fn from(s: &str) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Value

Converts to this type from the input type.
Source§

impl<V> From<Vec<V>> for Value
where V: Into<Value>,

Source§

fn from(items: Vec<V>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Value

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(n: i32) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(n: i64) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Value

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§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

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> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more