pub enum WhiskerValue {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
Bytes(Vec<u8>),
Array(Vec<WhiskerValue>),
Map(BTreeMap<String, WhiskerValue>),
Error(String),
}Expand description
Tagged-union variant set passed between Rust and the platform side — module args/returns and event payloads alike.
String/Bytes/Array/Map are Rust-allocated and dropped on
scope exit. Conversion to/from the C WhiskerValueRaw form
happens at the FFI boundary in whisker-driver.
This enum is intentionally closed (not #[non_exhaustive]): it
models a sealed tagged union mirroring the C WhiskerValueRaw
discriminator, and the FFI encoder in whisker-driver must handle
every variant exhaustively. Adding a variant is a deliberate,
breaking wire-format change touching both sides of the boundary, so
callers may rely on matching it exhaustively.
Variants§
Null
Bool(bool)
Int(i64)
Float(f64)
String(String)
Bytes(Vec<u8>)
Array(Vec<WhiskerValue>)
Map(BTreeMap<String, WhiskerValue>)
String-keyed map. BTreeMap for deterministic iteration
order — important for snapshot tests and the proc-macro
layer that codegen’s destructuring patterns based on
key order.
Error(String)
Bridge / platform reported failure. Carries a UTF-8
description; the proc macro lifts this into a typed
Result::Err.
Implementations§
Source§impl WhiskerValue
impl WhiskerValue
Sourcepub fn map<I, K>(entries: I) -> Self
pub fn map<I, K>(entries: I) -> Self
Convenience constructor that wraps a BTreeMap literal.
Lets test code write
WhiskerValue::map([("k", WhiskerValue::Int(1))]) without
importing BTreeMap.
Sourcepub fn args<I>(items: I) -> Selfwhere
I: IntoIterator<Item = WhiskerValue>,
pub fn args<I>(items: I) -> Selfwhere
I: IntoIterator<Item = WhiskerValue>,
Build the { "args": [ … ] } params object that Whisker module
element methods (@WhiskerUIMethod) decode — their forwarders
read positional arguments from params.args. Built-in Lynx
methods read named fields directly and use map
instead; this helper is for module-element handles like
VideoHandle invoking through the unified ElementRef::invoke.
Sourcepub fn as_error(&self) -> Option<&str>
pub fn as_error(&self) -> Option<&str>
Returns the Error message if self is the Error variant.
Convenience for callers that want to bail on any failure
without matching the variant manually.
Sourcepub fn deserialize_into<T: DeserializeOwned>(&self) -> Result<T, String>
pub fn deserialize_into<T: DeserializeOwned>(&self) -> Result<T, String>
Deserialize this value tree into a typed T.
Used by the typed-event layer: a Fn(TouchEvent) handler
receives the event body as a WhiskerValue, then
deserialize_into::<TouchEvent>() recovers the struct. On
failure (shape mismatch, missing required field) returns
Err with a human-readable message — the event binding logs
it together with the raw value rather than silently dropping
the handler call.
Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Lower this value tree into a serde_json::Value. In-memory
only — the target of deserialize_into.
Sourcepub fn from_json(v: Value) -> WhiskerValue
pub fn from_json(v: Value) -> WhiskerValue
Lift a serde_json::Value into a WhiskerValue.
Trait Implementations§
Source§impl Clone for WhiskerValue
impl Clone for WhiskerValue
Source§fn clone(&self) -> WhiskerValue
fn clone(&self) -> WhiskerValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WhiskerValue
impl Debug for WhiskerValue
Source§impl Default for WhiskerValue
impl Default for WhiskerValue
Source§fn default() -> WhiskerValue
fn default() -> WhiskerValue
Source§impl<'de> Deserialize<'de> for WhiskerValue
impl<'de> Deserialize<'de> for WhiskerValue
Source§fn 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>,
Source§impl From<&str> for WhiskerValue
impl From<&str> for WhiskerValue
Source§impl From<()> for WhiskerValue
impl From<()> for WhiskerValue
Source§impl From<String> for WhiskerValue
impl From<String> for WhiskerValue
Source§impl<T> From<Vec<T>> for WhiskerValuewhere
T: Into<WhiskerValue>,
impl<T> From<Vec<T>> for WhiskerValuewhere
T: Into<WhiskerValue>,
Source§impl From<bool> for WhiskerValue
impl From<bool> for WhiskerValue
Source§impl From<f32> for WhiskerValue
impl From<f32> for WhiskerValue
Source§impl From<f64> for WhiskerValue
impl From<f64> for WhiskerValue
Source§impl From<i32> for WhiskerValue
impl From<i32> for WhiskerValue
Source§impl From<i64> for WhiskerValue
impl From<i64> for WhiskerValue
Source§impl From<u32> for WhiskerValue
impl From<u32> for WhiskerValue
Source§impl PartialEq for WhiskerValue
impl PartialEq for WhiskerValue
Source§fn eq(&self, other: &WhiskerValue) -> bool
fn eq(&self, other: &WhiskerValue) -> bool
self and other values to be equal, and is used by ==.