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
impl TypeFamily
Sourcepub const fn new(name: &'static str) -> Self
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.
Sourcepub const fn with_doc(name: &'static str, doc: &'static str) -> Self
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.
Sourcepub fn fn_family() -> &'static Self
pub fn fn_family() -> &'static Self
Returns a reference to the type family of function-like objects, which are objects that have invocation capabilities.
Sourcepub fn package() -> &'static Self
pub fn package() -> &'static Self
Returns a reference to the type family of ScriptPackage objects.
Sourcepub fn is_nil(&self) -> bool
pub fn is_nil(&self) -> bool
Returns true if this family is the Nil Family.
Sourcepub fn is_dynamic(&self) -> bool
pub fn is_dynamic(&self) -> bool
Returns true if this family is the Dynamic Family.
Sourcepub fn is_fn(&self) -> bool
pub fn is_fn(&self) -> bool
Returns true if this family is the Functions Family.
Sourcepub fn is_package(&self) -> bool
pub fn is_package(&self) -> bool
Returns true if this family is the Packages Family.
Sourcepub fn is_number(&self) -> bool
pub fn is_number(&self) -> bool
Returns true if this family is the Numeric Family.
Trait Implementations§
Source§impl Debug for TypeFamily
impl Debug for TypeFamily
Source§impl Display for TypeFamily
impl Display for TypeFamily
impl Eq for TypeFamily
Source§impl From<&'static TypeFamily> for TypeHint
impl From<&'static TypeFamily> for TypeHint
Source§fn from(value: &'static TypeFamily) -> Self
fn from(value: &'static TypeFamily) -> Self
Source§impl Hash for TypeFamily
impl Hash for TypeFamily
Source§impl<'a> IntoIterator for &'a TypeFamily
impl<'a> IntoIterator for &'a TypeFamily
Source§impl PartialEq for TypeFamily
impl PartialEq for TypeFamily
Auto Trait Implementations§
impl Freeze for TypeFamily
impl RefUnwindSafe for TypeFamily
impl Send for TypeFamily
impl Sync for TypeFamily
impl Unpin for TypeFamily
impl UnsafeUnpin for TypeFamily
impl UnwindSafe for TypeFamily
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more