Skip to main content

ScriptTy

Enum ScriptTy 

Source
pub enum ScriptTy {
    Any,
    Unit,
    Bool,
    Int,
    Float,
    Str,
    Array(Box<ScriptTy>),
    Map(Box<ScriptTy>),
    Dynamic,
    Struct(ScriptStruct),
}
Expand description

The shape of one parameter or return value.

A host binds a typed parameter to its own type where it can (Rhai resolves a call by argument type) and checks the argument where it cannot (Lua binds variadically and raises on a mismatch). ScriptTy::Any accepts whatever the script passes, and ScriptTy::Dynamic says the same of a return that was meant to be open rather than left undeclared.

Variants are append-only; see SCRIPT_WIRE_VERSION.

Variants§

§

Any

Any value; no check. This is what a signature carries where nothing was declared, so an untyped return is read as a forgotten declaration.

§

Unit

No value (() in Rhai, nil in Lua, null in candela).

§

Bool

Boolean.

§

Int

Signed 64-bit integer.

§

Float

64-bit float.

§

Str

String.

§

Array(Box<ScriptTy>)

List whose elements carry the inner type.

§

Map(Box<ScriptTy>)

String-keyed map whose values carry the inner type.

§

Dynamic

Any value, declared on purpose: the result has no shape narrower than this one, as with a parsed JSON document. Every host treats it exactly as Any; the difference is that the author said so, which is what tells a deliberate open return from a missing one.

§

Struct(ScriptStruct)

A named set of fields with declared defaults, taken as one parameter: the shape a function’s options have. See ScriptStruct.

A parameter type only. Each host renders it in its own terms (a struct candela declares beside the function, a map on Rhai and Lua), and the body always receives a ScriptValue::Map holding every field.

Implementations§

Source§

impl ScriptTy

Source

pub fn is_dynamic(&self) -> bool

Whether this type names no shape a host can bind: Any because nothing was declared, Dynamic because what was declared has no fixed shape. Every host treats the two alike; the builtin table’s own check is what tells them apart.

Source

pub fn accepts(&self, value: &ScriptValue) -> bool

Whether value satisfies this type. A dynamic type accepts anything; an Array or Map also checks its elements.

An integer satisfies a declared float: every scripting language Lumen hosts spells 1 and 1.0 as the same literal kind, so seek(30) is the call an author writes. The reverse does not hold; a float where an integer is declared would silently drop its fraction.

Source

pub fn empty_value(&self) -> ScriptValue

The value a field of this type starts with when its struct declares none: 0, 0.0, false, "", an empty list or map, a nested struct’s own defaults, and unit for the open types. These are the values candela gives an undeclared field, so every host agrees.

Source

pub fn name(&self) -> &'static str

The name a host puts in a type-mismatch message.

Trait Implementations§

Source§

impl Clone for ScriptTy

Source§

fn clone(&self) -> ScriptTy

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 ScriptTy

Source§

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

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

impl<'de> Deserialize<'de> for ScriptTy

Source§

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

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

impl Display for ScriptTy

A type written the way candela writes it: int, float, bool, string, null, any, T[] for an array, {string: T} for a map, and a struct by its name. A struct name does not parse back: its fields are not in the spelling.

This is the spelling a declaration uses wherever a signature is written as text rather than built in Rust, so a function described in a data file reads the same as one a candela script declares. ScriptTy::Any and ScriptTy::Dynamic both write as any, and any reads back as ScriptTy::Dynamic: a type someone wrote down is a declared one.

Source§

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

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

impl FromStr for ScriptTy

Source§

type Err = ScriptTyError

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for ScriptTy

Source§

fn eq(&self, other: &ScriptTy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ScriptTy

Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ScriptTy

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,