pub enum VarType {
Str,
Bool,
Int,
Float,
List(Vec<VarDecl>),
Struct(Vec<VarDecl>),
Enum(Vec<VariantDecl>),
Tmpl(Vec<VarDecl>),
Option(Box<VarType>),
}Expand description
Expected type of a template variable.
Variants§
Str
str — expects a string value.
Bool
bool — expects a boolean value.
Int
int — expects an integer value.
Float
float — expects a floating-point value.
List(Vec<VarDecl>)
list(field = type, ...) — required fields per item.
Struct(Vec<VarDecl>)
struct(field = type, ...) — required fields.
Enum(Vec<VariantDecl>)
enum(Option1, Option2, ...) — expects one of these variants.
Tmpl(Vec<VarDecl>)
tmpl(field = type, ...) — expects a template with matching params.
Option(Box<VarType>)
option(T) — syntactic sugar for enum(Some(val = T), None).
Accepts Value::None or the inner T type directly.
Implementations§
Source§impl VarType
impl VarType
Sourcepub fn is_displayable(&self) -> bool
pub fn is_displayable(&self) -> bool
Returns true if this type can be directly displayed via {{ expr }}.
Only scalar types (str, int, float, bool) are displayable.
Compound types (list, struct, enum, tmpl, option) must be
accessed through iteration, field access, kind(), has(), or
{% match %} instead.
Sourcepub fn matches(&self, value: &Value) -> bool
pub fn matches(&self, value: &Value) -> bool
Returns true if value is compatible with this declared type.
- Scalar types match their corresponding
Valuevariant. List(fields)matchesValue::List; iffieldsis non-empty, every item must be aStructwith all required keys and matching value types (recursive).Struct(fields)matchesValue::Struct; required keys must be present with matching value types (recursive).Enum(variants)matches unit variants asValue::Str, struct variants asValue::Structwith__kind__+ typed fields.
Sourcepub fn check(&self, value: &Value) -> Result<(), TypeCheckError>
pub fn check(&self, value: &Value) -> Result<(), TypeCheckError>
Validate value against this type, returning a structured error with
the path to the first mismatch on failure.
Uses a two-pass strategy: a fast discriminant-only check first (zero allocations), falling back to the full path-building check only when a mismatch is detected.
§Errors
Returns TypeCheckError with the dotted path to the mismatched field,
the expected type, the actual type, and a preview of the actual value.
Source§impl VarType
impl VarType
Sourcepub fn is_option(&self) -> bool
pub fn is_option(&self) -> bool
Returns true if this type is an option(T).
option is a first-class type: a literal enum(Some(val = T), None)
is an ordinary enum, not an option. Use option(T) for options.
Sourcepub fn option_inner_type(&self) -> Option<&VarType>
pub fn option_inner_type(&self) -> Option<&VarType>
If this type is option(T), returns the inner T type.
Trait Implementations§
impl Eq for VarType
impl StructuralPartialEq for VarType
Auto Trait Implementations§
impl Freeze for VarType
impl RefUnwindSafe for VarType
impl Send for VarType
impl Sync for VarType
impl Unpin for VarType
impl UnsafeUnpin for VarType
impl UnwindSafe for VarType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.