pub enum Value<'gc, C: CustomTypes<S>, S: System<C>> {
    Bool(bool),
    Number(Number),
    String(Rc<String>),
    Image(Rc<Vec<u8>>),
    Audio(Rc<Vec<u8>>),
    Native(Rc<C::NativeValue>),
    List(Gc<'gc, RefLock<VecDeque<Value<'gc, C, S>>>>),
    Closure(Gc<'gc, RefLock<Closure<'gc, C, S>>>),
    Entity(Gc<'gc, RefLock<Entity<'gc, C, S>>>),
}
Expand description

Any primitive value.

Variants§

§

Bool(bool)

A primitive boolean value.

§

Number(Number)

A primitive numeric value. Snap! and NetsBlox use 64-bit floating point values for all numbers.

§

String(Rc<String>)

A primitive string value, which is an immutable reference type.

§

Image(Rc<Vec<u8>>)

An image stored as a binary buffer.

§

Audio(Rc<Vec<u8>>)

An audio clip stored as as a binary buffer.

§

Native(Rc<C::NativeValue>)

A reference to a native object handle produced by System.

§

List(Gc<'gc, RefLock<VecDeque<Value<'gc, C, S>>>>)

A primitive list type, which is a mutable reference type.

§

Closure(Gc<'gc, RefLock<Closure<'gc, C, S>>>)

A closure/lambda function. This contains information about the closure’s bytecode location, parameters, and captures from the parent scope.

§

Entity(Gc<'gc, RefLock<Entity<'gc, C, S>>>)

A reference to an Entity in the environment.

Implementations§

source§

impl<'gc, C: CustomTypes<S>, S: System<C>> Value<'gc, C, S>

source

pub fn from_json(mc: &Mutation<'gc>, value: Json) -> Result<Self, FromJsonError>

Create a new Value from a Json value.

source

pub fn to_json(&self) -> Result<Json, ToJsonError<C, S>>

Converts a Value into Json. Note that not all values can be converted to json (e.g., cyclic lists or complex types).

source

pub fn identity(&self) -> Identity<'gc, C, S>

Returns a value representing this object that implements Eq such that two values are equal if and only if they are references to the same object. This is primarily useful for testing for reference equality of lists.

source

pub fn to_bool(&self) -> Result<bool, ConversionError<C, S>>

Attempts to interpret this value as a bool.

source

pub fn to_number(&self) -> Result<Number, ConversionError<C, S>>

Attempts to interpret this value as a number.

source

pub fn to_string(&self) -> Result<Cow<'_, str>, ConversionError<C, S>>

Attempts to interpret this value as a string.

source

pub fn as_image(&self) -> Result<&Rc<Vec<u8>>, ConversionError<C, S>>

Attempts to interpret this value as an image.

source

pub fn as_list( &self ) -> Result<Gc<'gc, RefLock<VecDeque<Value<'gc, C, S>>>>, ConversionError<C, S>>

Attempts to interpret this value as a list.

source

pub fn as_closure( &self ) -> Result<Gc<'gc, RefLock<Closure<'gc, C, S>>>, ConversionError<C, S>>

Attempts to interpret this value as a closure.

source

pub fn as_entity( &self ) -> Result<Gc<'gc, RefLock<Entity<'gc, C, S>>>, ConversionError<C, S>>

Attempts to interpret this value as an entity.

Trait Implementations§

source§

impl<'gc, C: CustomTypes<S>, S: System<C>> Clone for Value<'gc, C, S>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, _source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> Collect for Value<'gc, C, S>where bool: 'static, Number: 'static, Rc<String>: 'static, Rc<Vec<u8>>: 'static, Rc<C::NativeValue>: 'static,

source§

fn needs_trace() -> bool

As an optimization, if this type can never hold a Gc pointer and trace is unnecessary to call, you may implement this method and return false. The default implementation returns true, signaling that Collect::trace must be called.
source§

fn trace(&self, cc: &Collection)

Must call Collect::trace on all held Gc pointers. If this type holds inner types that implement Collect, a valid implementation would simply call Collect::trace on all the held values to ensure this.
source§

impl<C: CustomTypes<S>, S: System<C>> Debug for Value<'_, C, S>

source§

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

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

impl<'gc, C: CustomTypes<S>, S: System<C>> From<CheckedFloat<f64, NumberChecker>> for Value<'gc, C, S>

source§

fn from(v: Number) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> From<Gc<'gc, RefLock<Closure<'gc, C, S>>>> for Value<'gc, C, S>

source§

fn from(v: Gc<'gc, RefLock<Closure<'gc, C, S>>>) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> From<Gc<'gc, RefLock<Entity<'gc, C, S>>>> for Value<'gc, C, S>

source§

fn from(v: Gc<'gc, RefLock<Entity<'gc, C, S>>>) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> From<Gc<'gc, RefLock<VecDeque<Value<'gc, C, S>, Global>>>> for Value<'gc, C, S>

source§

fn from(v: Gc<'gc, RefLock<VecDeque<Value<'gc, C, S>>>>) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> From<Rc<String, Global>> for Value<'gc, C, S>

source§

fn from(v: Rc<String>) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> From<bool> for Value<'gc, C, S>

source§

fn from(v: bool) -> Self

Converts to this type from the input type.
source§

impl<'gc, C: CustomTypes<S>, S: System<C>> GetType for Value<'gc, C, S>

§

type Output = Type<C, S>

source§

fn get_type(&self) -> Self::Output

Gets the type of value that is stored.

Auto Trait Implementations§

§

impl<'gc, C, S> !RefUnwindSafe for Value<'gc, C, S>

§

impl<'gc, C, S> !Send for Value<'gc, C, S>

§

impl<'gc, C, S> !Sync for Value<'gc, C, S>

§

impl<'gc, C, S> Unpin for Value<'gc, C, S>

§

impl<'gc, C, S> !UnwindSafe for Value<'gc, C, S>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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