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.