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§
source§impl Value
impl Value
sourcepub fn new(from: impl IntoValue<EngineUse = DoesNotUseEngine>) -> Self
pub fn new(from: impl IntoValue<EngineUse = DoesNotUseEngine>) -> Self
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);
Trait Implementations§
source§impl IntoValue for Value
impl IntoValue for Value
§type EngineUse = DoesNotUseEngine
type EngineUse = DoesNotUseEngine
IntoValue
uses an engine or not.source§impl TryFromValue for Value
impl TryFromValue for Value
source§fn try_from_value(value: &Value, _: &Environment) -> Result<Self, Error>
fn try_from_value(value: &Value, _: &Environment) -> Result<Self, Error>
Error
on failure.