pub enum Value {
}Expand description
Stable JSON representation shared by native and WebAssembly hosts.
Variants§
Enum(Box<EnumValue>)
A nominal algebraic case or a built-in Res/Opt value with checked payloads.
Matching inspects the case and binds payload values. There is no null value or exception syntax; recoverable operation failures are ordinary Err values.
Number(f64)
A finite IEEE 754 binary64 scalar with canonical language type f64.
Number remains a source alias for f64 and this host representation remains
compatible with native spatial interfaces. Literals without numeric context
default to f64. Exact integer widths and f16/f32/f128 use Scalar instead.
Numeric variables never implicitly change dtype; use .convert[T]() for an
explicit conversion, which rejects overflow and loss of information.
Scalar(Scalar)
An exact width-specific numeric scalar.
Supported widths are u8 through u128, i8 through i128, f16, f32, and f128. Integer arithmetic checks overflow and floating arithmetic rounds once to the declared IEEE format. Serialized decimal strings preserve values across JSON hosts without passing wide integers through binary64.
Tensor(Box<Tensor>)
An immutable packed Tensor[T] with shared storage and checked shape/stride views.
A tensor stores one numeric dtype and a runtime shape. Comma-separated indices
select scalar elements; slices preserve tensors and share their allocation.
Arithmetic broadcasts trailing dimensions; @ multiplies matrices and batches.
Arithmetic and indexing return Res; get returns Opt for a scalar lookup.
Dtypes must match, with contextual typing reserved for literal operands.
Bin(Bin)
Immutable bytes without an implied text encoding.
Cloning shares a packed Arc allocation. bytes constructs Bin from List[u8],
Str.utf8 encodes text, and Bin.decode validates UTF-8 with a Res result.
Indexing returns Res[u8, DataError]; slicing produces Res[Bin, DataError].
Concatenation creates independent data and respects byte limits.
Bool(bool)
A Boolean value used by conditions and short-circuit expressions.
Bool stores a Rust bool and has exactly two values: true and false.
if and while require Bool; numeric zero and empty collections do not
act as false. and and or evaluate their right side only when needed.
Text(Str)
Immutable UTF-8 text with canonical language type Str (String is an alias).
Clones share an Arc allocation. Concatenation creates a new value without
implicit conversion. len, indexing, and slices count Unicode scalar values,
while allocation limits count UTF-8 bytes. utf8 encodes to Bin and decode
validates Bin as UTF-8. Text is the separate visible scene component.
List(Vec<Value>)
An ordered owned collection whose elements share one language type.
List[T] stores Rust Vec<Value> data. The compiler retains T and the
runtime checks elements at typed boundaries. An empty literal needs a
contextual element type, such as let values: List[f64] = [];.
Indexing starts at zero and rejects out-of-range indices. Assignment
copies a list value; .append(value) returns a new list. .get(index)
returns Opt[T], while indexing returns Res[T, DataError]. Collection length and
nested values remain subject to the embedding host’s Limits.
Record(RecordValue)
A nominal type instance with checked fields.
A RecordValue owns its field map. Constructing a type creates data; spawn attaches it to an ECS entity. Prelude types use this same representation as user types, rather than separate Rust struct aliases.
Function(Box<FunctionValue>)
A statically typed callable with inspectable identity.
FunctionValue stores a checked signature and target identity, not executable code or a raw pointer. Language and native function values use the same argument and result validation. Mutating component methods use bind.
ComponentReference(ComponentReference)
A typed entity/component identity used to capture live component methods.
ComponentReference[T] pairs a Rust entity ID with a canonical concrete
type name. bind[T](entity) validates that the component exists; method
calls resolve it again and commit accepted receiver changes transactionally.
This is an interpreter handle, not a Rust borrow or raw memory reference. Access component data with get and set; invoke methods through the reference. Invoking a reference after its entity disappears is an error.
Entity(u64)
An opaque ECS identity created by spawn.
Entity stores a Rust u64 handle. IDs are allocated in creation order
and cannot be constructed from a Number in the language. Copying a handle
keeps the same identity; it does not duplicate the entity or its components.
Use get, set, has and bind with a concrete component type. A handle can outlive its entity, but subsequent access to a removed entity is rejected.
Unit
The single empty value returned by procedures.
Unit is represented by the payload-free Rust Value::Unit variant and
spelled () in the language. A function returning Unit may end without
a value or use ret;. Unit is not null, an absent field, or an optional value.
Implementations§
Source§impl Value
impl Value
Sourcepub fn algebraic(value: EnumValue) -> Self
pub fn algebraic(value: EnumValue) -> Self
Construct an algebraic value for a host boundary, where its type and payload are validated.
Sourcepub fn record(
class: impl Into<String>,
fields: impl IntoIterator<Item = (String, Value)>,
) -> Self
pub fn record( class: impl Into<String>, fields: impl IntoIterator<Item = (String, Value)>, ) -> Self
Assemble a record for a host input. Machine entry points validate its declared fields.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSync for T
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);impl<T> Scalar for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.