Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Undef,
    Bool(bool),
    Int(i64),
    Float(f64),
    Str(Arc<String>),
    Array(Vec<Value>),
    Hash(HashMap<String, Value>),
    Status(i32),
    Ref(Box<Value>),
    NativeFn(u16),
    Obj(u32),
}
Expand description

Core value type — what lives on the stack and in variables.

Designed to be small (1 word tag + 1-2 words payload) so the dispatch loop stays cache-friendly.

Variants§

§

Undef

No value / uninitialized

§

Bool(bool)

Boolean (from conditionals, [[ ]], etc.)

§

Int(i64)

64-bit signed integer

§

Float(f64)

64-bit float

§

Str(Arc<String>)

Heap-allocated string (Arc for cheap clone in closures)

§

Array(Vec<Value>)

Ordered array of values

§

Hash(HashMap<String, Value>)

Key-value associative array

§

Status(i32)

Exit status code (shell-specific but universal enough)

§

Ref(Box<Value>)

Reference to another value (for pass-by-reference, nested structures)

§

NativeFn(u16)

Native function pointer (builtin dispatch)

§

Obj(u32)

Opaque handle into a frontend object heap (e.g. elisp cons/symbol/vector cells). The frontend’s extension handler/host owns the pointed-to object; fusevm just carries the handle through the stack, slots, and globals. Identity-comparable (the handle is the identity), which is what elisp eq/setcar need and Array could not provide.

Implementations§

Source§

impl Value

Source

pub fn int(n: i64) -> Value

Construct an integer Value::Int(n).

Source

pub fn float(f: f64) -> Value

Construct a float Value::Float(f).

Source

pub fn str(s: impl Into<String>) -> Value

Construct a string Value::Str from any type that converts to String. The payload is wrapped in Arc so clones are cheap.

Source

pub fn bool(b: bool) -> Value

Construct a boolean Value::Bool(b).

Source

pub fn array(v: Vec<Value>) -> Value

Construct an array Value::Array(v).

Source

pub fn hash(m: HashMap<String, Value>) -> Value

Construct a hash Value::Hash(m).

Source

pub fn status(code: i32) -> Value

Construct a Value::Status(code) — used for $? / pipeline-exit values so a numeric exit code stays distinguishable from plain Value::Int(n) in is_truthy / display logic.

Source

pub fn is_truthy(&self) -> bool

Truthiness: 0, 0.0, “”, undef, empty array/hash are false.

Source

pub fn to_int(&self) -> i64

Coerce to i64.

Source

pub fn to_float(&self) -> f64

Coerce to f64.

Source

pub fn to_str(&self) -> String

Coerce to string.

Source

pub fn as_str_cow(&self) -> Cow<'_, str>

Coerce to string, borrowing when possible to avoid allocation. Returns Cow::Borrowed for Str, Undef, Bool, Hash, Ref variants.

Source

pub fn len(&self) -> usize

String length or array length or hash size.

Source

pub fn is_empty(&self) -> bool

len() == 0 shorthand — clippy requires this when len is pub.

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<'de> Deserialize<'de> for Value

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Value, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl Hash for Value

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
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 Serialize for Value

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> Instrument for T

Source§

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

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

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.

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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