pub enum Value {
    Nil,
    False,
    True,
    Number(f64),
    String(Gc<String>),
    Function(Hidden<Closure>),
    Struct(Hidden<Struct>),
    Trait(Hidden<Trait>),
    List(Hidden<List>),
    Dict(Hidden<Dict>),
    UserData(Gc<Box<dyn UserData>>),
}
Expand description

A dynamically typed value.

Variants

Nil

The nil literal.

False

The false literal.

True

The true literal.

Do note that despite booleans using two different enum variants, they have the same type.

Number(f64)

A Number value.

String(Gc<String>)

A GC’d String.

Function(Hidden<Closure>)

A function.

Functions can be called with Engine::call.

Struct(Hidden<Struct>)

An opaque struct.

Trait(Hidden<Trait>)

An opaque trait.

List(Hidden<List>)

A list.

Lists are opaque to the Rust API and must be converted into a typed Vec<T>.

Dict(Hidden<Dict>)

A dict.

Dicts are opaque to the Rust API, no conversion function currently exists for them.

UserData(Gc<Box<dyn UserData>>)

Arbitrarily typed user data.

Implementations

Creates a new value from any compatible type.

Note that this can only ever be used with types that can be created without the help of an Engine; in particular, this function is incapable of creating user data. See Engine::create_value for more information and a less limited version.

Examples
use mica::Value;

let value = Value::new(1.0);

As mentioned before, Value::new cannot be used to create user data values:

use mica::Value;

struct Example;
impl UserData for Example {}

let value = Value::new(Example);

Returns the name of this value’s type.

Returns whether the value is falsy.

Returns whether the value is truthy.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Specifies whether this implementation of IntoValue uses an engine or not.
Tries to perform the conversion, returning an Error on failure.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.