pub struct NativeClass {
pub id: ClassId,
pub symbol: Symbol,
pub constructor: FunctionObject,
pub read_constructor: Option<FunctionObject>,
pub instance_shape: Option<Arc<dyn Shape>>,
pub parent_symbols: Vec<Symbol>,
pub members: Vec<MemberFunction>,
}Expand description
Host-defined class: a constructor, optional shapes, parents, and members
implementing the kernel Class and Callable contracts.
Fields§
§id: ClassIdStable id assigned to the class.
symbol: SymbolSymbol the class is registered under.
constructor: FunctionObjectConstructor invoked when the class is called.
read_constructor: Option<FunctionObject>Constructor used for read-construct literals, if distinct from the call constructor.
instance_shape: Option<Arc<dyn Shape>>Shape that instances of the class are expected to satisfy.
parent_symbols: Vec<Symbol>Symbols of the class’s parent classes.
members: Vec<MemberFunction>Member accessors exposed by the class.
Implementations§
Source§impl NativeClass
impl NativeClass
Sourcepub fn new(
id: ClassId,
symbol: Symbol,
constructor: FunctionObject,
instance_shape: Option<Arc<dyn Shape>>,
member_fields: Vec<Symbol>,
) -> Self
pub fn new( id: ClassId, symbol: Symbol, constructor: FunctionObject, instance_shape: Option<Arc<dyn Shape>>, member_fields: Vec<Symbol>, ) -> Self
Creates a class with the given id, symbol, constructor, instance shape, and member fields.
Sourcepub fn with_read_constructor(
self,
read_constructor: Option<FunctionObject>,
) -> Self
pub fn with_read_constructor( self, read_constructor: Option<FunctionObject>, ) -> Self
Sets the read-construct constructor and returns the updated class.
Sourcepub fn with_parents(self, parent_symbols: Vec<Symbol>) -> Self
pub fn with_parents(self, parent_symbols: Vec<Symbol>) -> Self
Sets the parent symbols and returns the updated class.
Sourcepub fn constructor(&self) -> &FunctionObject
pub fn constructor(&self) -> &FunctionObject
Returns the class’s call constructor.
Sourcepub fn member_names(&self) -> impl Iterator<Item = &Symbol>
pub fn member_names(&self) -> impl Iterator<Item = &Symbol>
Iterates over the field names of the class’s members.
Sourcepub fn member_functions(&self) -> &[MemberFunction]
pub fn member_functions(&self) -> &[MemberFunction]
Returns the class’s member accessors.
Sourcepub fn member_function(&self, field: &Symbol) -> Option<&MemberFunction>
pub fn member_function(&self, field: &Symbol) -> Option<&MemberFunction>
Looks up a member accessor by field name.
Sourcepub fn constructor_shape_arc(&self) -> Option<Arc<dyn Shape>>
pub fn constructor_shape_arc(&self) -> Option<Arc<dyn Shape>>
Builds the combined argument shape covering all constructor cases.
Trait Implementations§
Source§impl Callable for NativeClass
impl Callable for NativeClass
Source§fn call(&self, cx: &mut Cx, args: Args) -> Result<Value>
fn call(&self, cx: &mut Cx, args: Args) -> Result<Value>
Args.Source§fn browse_args_shape(&self, cx: &mut Cx) -> Result<Option<ShapeRef>>
fn browse_args_shape(&self, cx: &mut Cx) -> Result<Option<ShapeRef>>
Source§impl Class for NativeClass
impl Class for NativeClass
Source§fn parents(&self, cx: &mut Cx) -> Result<Vec<ClassRef>>
fn parents(&self, cx: &mut Cx) -> Result<Vec<ClassRef>>
Source§fn constructor_shape(&self, cx: &mut Cx) -> Result<ShapeRef>
fn constructor_shape(&self, cx: &mut Cx) -> Result<ShapeRef>
Source§fn instance_shape(&self, cx: &mut Cx) -> Result<ShapeRef>
fn instance_shape(&self, cx: &mut Cx) -> Result<ShapeRef>
Source§fn read_constructor(&self, _cx: &mut Cx) -> Result<Option<ReadConstructorRef>>
fn read_constructor(&self, _cx: &mut Cx) -> Result<Option<ReadConstructorRef>>
Source§impl Clone for NativeClass
impl Clone for NativeClass
Source§fn clone(&self) -> NativeClass
fn clone(&self) -> NativeClass
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Object for NativeClass
impl Object for NativeClass
Source§fn display(&self, _cx: &mut Cx) -> Result<String>
fn display(&self, _cx: &mut Cx) -> Result<String>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.Source§impl ObjectCompat for NativeClass
impl ObjectCompat for NativeClass
Source§fn class(&self, cx: &mut Cx) -> Result<ClassRef>
fn class(&self, cx: &mut Cx) -> Result<ClassRef>
Source§fn as_expr(&self, _cx: &mut Cx) -> Result<Expr>
fn as_expr(&self, _cx: &mut Cx) -> Result<Expr>
Source§fn as_table(&self, cx: &mut Cx) -> Result<Value>
fn as_table(&self, cx: &mut Cx) -> Result<Value>
Source§fn as_callable(&self) -> Option<&dyn Callable>
fn as_callable(&self) -> Option<&dyn Callable>
Source§fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
Source§fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
Source§fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
Source§fn as_number_value(&self) -> Option<&dyn NumberValue>
fn as_number_value(&self) -> Option<&dyn NumberValue>
Source§fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
Source§fn as_sequence(&self) -> Option<&dyn Sequence>
fn as_sequence(&self) -> Option<&dyn Sequence>
Source§fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
Source§fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
Source§fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
Auto Trait Implementations§
impl !RefUnwindSafe for NativeClass
impl !UnwindSafe for NativeClass
impl Freeze for NativeClass
impl Send for NativeClass
impl Sync for NativeClass
impl Unpin for NativeClass
impl UnsafeUnpin for NativeClass
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,
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 more