Skip to main content

WhiskerValue

Enum WhiskerValue 

Source
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

Source

pub fn map<I, K>(entries: I) -> Self
where I: IntoIterator<Item = (K, WhiskerValue)>, K: Into<String>,

Convenience constructor that wraps a BTreeMap literal. Lets test code write WhiskerValue::map([("k", WhiskerValue::Int(1))]) without importing BTreeMap.

Source

pub fn args<I>(items: I) -> Self
where 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.

Source

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.

Source

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.

Source

pub fn to_json(&self) -> Value

Lower this value tree into a serde_json::Value. In-memory only — the target of deserialize_into.

Source

pub fn from_json(v: Value) -> WhiskerValue

Lift a serde_json::Value into a WhiskerValue.

Trait Implementations§

Source§

impl Clone for WhiskerValue

Source§

fn clone(&self) -> WhiskerValue

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 WhiskerValue

Source§

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

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

impl Default for WhiskerValue

Source§

fn default() -> WhiskerValue

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

impl<'de> Deserialize<'de> for WhiskerValue

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for WhiskerValue

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for WhiskerValue

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<String> for WhiskerValue

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for WhiskerValue
where T: Into<WhiskerValue>,

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for WhiskerValue

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for WhiskerValue

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for WhiskerValue

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for WhiskerValue

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for WhiskerValue

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for WhiskerValue

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for WhiskerValue

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for WhiskerValue

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for WhiskerValue

Source§

impl TryFrom<WhiskerValue> for ()

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<WhiskerValue> for bool

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<WhiskerValue> for i64

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<WhiskerValue> for i32

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<WhiskerValue> for f64

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<WhiskerValue> for f32

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<WhiskerValue> for String

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<WhiskerValue> for Vec<u8>

Source§

type Error = String

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

fn try_from(v: WhiskerValue) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

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.