Skip to main content

TypeFamily

Struct TypeFamily 

Source
pub struct TypeFamily(/* private fields */);
Expand description

A set of semantically related types.

Types that can be type-casted to each other to some extent form a family of types. The semantic analyzer typically treats them as a single unified type, and the LSP server usually displays the type family to which a specific type belongs.

This approach simplifies interoperability between Rust types in scripts. For example, usize, f32, and other Rust built-in primitive numeric types form the number family of types. The script engine performs automatic type conversions between these types, allowing the end user to work with each specific numeric type as a general “number”.

When you export a type using the export macro, the Script Engine automatically creates a new type family containing just that type.

However, you can manually associate a type with an existing family using the #[export(family(<family_reference>))] macro option.

To introduce a new type family, consider using the type_family declarative macro.

The TypeFamily object provides functions to explore the types associated with the family.

The IntoIterator implementation for this object iterates over each TypeMeta associated with this family.

The Debug and Display implementations print the name of the family, and (in alternate mode) enumerate the names of all associated types.

Implementations§

Source§

impl TypeFamily

Source

pub const fn new(name: &'static str) -> Self

Creates a new TypeFamily with the specified name and without documentation.

Instances of type families should typically be stored in statics:

static FOO_FAMILY: TypeFamily = TypeFamily::new("foo");

It is recommended to use the type_family declarative macro to declare type families instead.

Source

pub const fn with_doc(name: &'static str, doc: &'static str) -> Self

Similar to the new constructor, but allows specifying RustDoc documentation for the type family through the doc parameter.

The doc string is expected to be raw Markdown documentation text.

Source

pub fn nil() -> &'static Self

Returns a reference to the type family of the Nil type.

Source

pub fn dynamic() -> &'static Self

Returns a reference to the type family of the dynamic type.

Source

pub fn fn_family() -> &'static Self

Returns a reference to the type family of function-like objects, which are objects that have invocation capabilities.

Source

pub fn package() -> &'static Self

Returns a reference to the type family of ScriptPackage objects.

Source

pub fn number() -> &'static Self

Returns a reference to the type family of numeric objects.

The usize, f32, and other Rust built-in numeric types belong to this family.

Source

pub fn is_nil(&self) -> bool

Returns true if this family is the Nil Family.

Source

pub fn is_dynamic(&self) -> bool

Returns true if this family is the Dynamic Family.

Source

pub fn is_fn(&self) -> bool

Returns true if this family is the Functions Family.

Source

pub fn is_package(&self) -> bool

Returns true if this family is the Packages Family.

Source

pub fn is_number(&self) -> bool

Returns true if this family is the Numeric Family.

Source

pub fn len(&self) -> usize

Returns the number of types associated with this family.

Source

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

Returns the user-facing name of this family.

Source

pub fn doc(&self) -> Option<&'static str>

Returns the RustDoc documentation for this type family. Returns None if the family does not have specified documentation.

Source

pub fn includes(&self, ty: &TypeId) -> bool

Returns true if this type family contains a Rust type with the specified TypeId.

Trait Implementations§

Source§

impl Debug for TypeFamily

Source§

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

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

impl Display for TypeFamily

Source§

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

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

impl Eq for TypeFamily

Source§

impl From<&'static TypeFamily> for TypeHint

Source§

fn from(value: &'static TypeFamily) -> Self

Converts to this type from the input type.
Source§

impl Hash for TypeFamily

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> IntoIterator for &'a TypeFamily

Source§

type Item = &'static TypeMeta

The type of the elements being iterated over.
Source§

type IntoIter = TypeFamilyIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for TypeFamily

Source§

fn eq(&self, other: &Self) -> 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.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToCompactString for T
where T: Display,

Source§

fn to_compact_string(&self) -> CompactString

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