[−][src]Trait rosy::Mixin
Required methods
fn to_class(self) -> Result<Class, Module>
Returns self
as a Class
if it is one or a Module
otherwise.
fn to_module(self) -> Result<Module, Class>
Returns self
as a Module
if it is one or a Class
otherwise.
Provided methods
fn include(self, module: Module)
Embeds the contents of module
in self
.
#[must_use]
fn includes(self, module: Module) -> bool
Returns whether self
or one of its ancestors includes module
.
This is equivalent to the include?
method.
fn included_modules(self) -> Array<Module>
Returns an array of the modules included in self
.
fn prepend(self, module: Module)
Prepends module
in self
.
fn def_class(self, name: impl Into<SymbolId>) -> Result<Class, DefMixinError>
Defines a new class under self
with name
.
fn def_subclass<S: Object>(
self,
superclass: Class<S>,
name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
self,
superclass: Class<S>,
name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
Defines a new subclass of superclass
under self
with name
.
fn get_class(self, name: impl Into<SymbolId>) -> Option<Class>
Returns the existing Class
with name
in self
.
unsafe fn get_class_unchecked(self, name: impl Into<SymbolId>) -> Class
Returns the existing Class
with name
in self
.
Safety
This method does not:
- Check whether an item for
name
exists (an exception will be thrown if this is the case) - Check whether the returned item for
name
is actually aClass
fn def_module(self, name: impl Into<SymbolId>) -> Result<Module, DefMixinError>
Defines a new module under self
with name
.
fn get_module(self, name: impl Into<SymbolId>) -> Option<Module>
Returns the existing Module
with name
in self
.
unsafe fn get_module_unchecked(self, name: impl Into<SymbolId>) -> Module
Returns the existing Module
with name
in self
.
Safety
This method does not:
- Check whether an item for
name
exists (an exception will be thrown if this is the case) - Check whether the returned item for
name
is actually aModule
fn has_const(self, name: impl Into<SymbolId>) -> bool
Returns whether a constant for name
is defined in self
, or in some
parent class if not self
.
fn get_const(self, name: impl Into<SymbolId>) -> AnyObject
Returns the constant value for name
in self
, or in some parent class
if not self
.
Exception Handling
If name
is an uninitialized variable, a NameError
exception will be
raised. If you're unsure whether name
exists, either check
has_const
or surround a call to this method in a
protected
closure.
fn set_const(self, name: impl Into<SymbolId>, val: impl Into<AnyObject>)
Sets the value a constant for name
in self
to val
.
fn remove_const(self, name: impl Into<SymbolId>) -> AnyObject
Removes the constant value for name
, returning it.
Exception Handling
If the constant for name
cannot be removed, an exception is raised.
fn has_class_var(self, var: impl Into<SymbolId>) -> bool
Returns whether the class-level var
is defined in self
.
fn get_class_var(self, var: impl Into<SymbolId>) -> AnyObject
Returns the class-level var
in self
.
Exception Handling
If var
is an uninitialized variable, a NameError
exception will be
raised. If you're unsure whether var
exists, either check
has_class_var
or surround a call to this
method in a protected
closure.
use rosy::{Class, Object, Mixin, protected}; let class = Class::array(); let error = protected(|| class.get_class_var("@@hello")).unwrap_err(); assert!(error.is_name_error());
fn set_class_var<K, V>(self, key: K, val: V) -> Result where
K: Into<SymbolId>,
V: Into<AnyObject>,
K: Into<SymbolId>,
V: Into<AnyObject>,
Sets the class-level var
in self
to val
.
unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V) where
K: Into<SymbolId>,
V: Into<AnyObject>,
K: Into<SymbolId>,
V: Into<AnyObject>,
Sets the class-level var for key
in self
to val
.
Safety
The caller must ensure that self
is not frozen or else a FrozenError
exception will be raised.
fn def_attr_reader<N: Into<SymbolId>>(self, name: N) -> Result
Defines an read-only attribute on self
with name
.
unsafe fn def_attr_reader_unchecked<N: Into<SymbolId>>(self, name: N)
Defines an read-only attribute on self
with name
.
Safety
The caller must ensure that self
is not frozen or else a FrozenError
exception will be raised.
fn def_attr_writer<N: Into<SymbolId>>(self, name: N) -> Result
Defines a write-only attribute on self
with name
.
unsafe fn def_attr_writer_unchecked<N: Into<SymbolId>>(self, name: N)
Defines a write-only attribute on self
with name
.
Safety
The caller must ensure that self
is not frozen or else a FrozenError
exception will be raised.
fn def_attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result
Defines a read-write attribute on self
with name
.
unsafe fn def_attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N)
Defines a read-write attribute on self
with name
.
Safety
The caller must ensure that self
is not frozen or else a FrozenError
exception will be raised.
unsafe fn eval(self, args: impl EvalArgs) -> AnyObject
Evaluates args
in the context of self
.
See the docs for EvalArgs
for more info.
Safety
Code executed from args
may void the type safety of objects accessible
from Rust. For example, if one calls push
on an Array<A>
with an
object of type B
, then the inserted object will be treated as being of
type A
.
An exception may be raised by the code or by args
being invalid.
unsafe fn eval_protected(self, args: impl EvalArgs) -> Result<AnyObject>
Evaluates args
in the context of self
, returning any raised
exceptions.
See the docs for EvalArgs
for more info.
Safety
Code executed from args
may void the type safety of objects accessible
from Rust. For example, if one calls push
on an Array<A>
with an
object of type B
, then the inserted object will be treated as being of
type A
.
Implementors
impl Mixin for Class
[src]
fn to_class(self) -> Result<Class, Module>
[src]
fn to_module(self) -> Result<Module, Class>
[src]
fn include(self, module: Module)
[src]
#[must_use]
fn includes(self, module: Module) -> bool
[src]
fn included_modules(self) -> Array<Module>
[src]
fn prepend(self, module: Module)
[src]
fn def_class(self, name: impl Into<SymbolId>) -> Result<Class, DefMixinError>
[src]
fn def_subclass<S: Object>(
self,
superclass: Class<S>,
name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
[src]
self,
superclass: Class<S>,
name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
fn get_class(self, name: impl Into<SymbolId>) -> Option<Class>
[src]
unsafe fn get_class_unchecked(self, name: impl Into<SymbolId>) -> Class
[src]
fn def_module(self, name: impl Into<SymbolId>) -> Result<Module, DefMixinError>
[src]
fn get_module(self, name: impl Into<SymbolId>) -> Option<Module>
[src]
unsafe fn get_module_unchecked(self, name: impl Into<SymbolId>) -> Module
[src]
fn has_const(self, name: impl Into<SymbolId>) -> bool
[src]
fn get_const(self, name: impl Into<SymbolId>) -> AnyObject
[src]
fn set_const(self, name: impl Into<SymbolId>, val: impl Into<AnyObject>)
[src]
fn remove_const(self, name: impl Into<SymbolId>) -> AnyObject
[src]
fn has_class_var(self, var: impl Into<SymbolId>) -> bool
[src]
fn get_class_var(self, var: impl Into<SymbolId>) -> AnyObject
[src]
fn set_class_var<K, V>(self, key: K, val: V) -> Result where
K: Into<SymbolId>,
V: Into<AnyObject>,
[src]
K: Into<SymbolId>,
V: Into<AnyObject>,
unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V) where
K: Into<SymbolId>,
V: Into<AnyObject>,
[src]
K: Into<SymbolId>,
V: Into<AnyObject>,
fn def_attr_reader<N: Into<SymbolId>>(self, name: N) -> Result
[src]
unsafe fn def_attr_reader_unchecked<N: Into<SymbolId>>(self, name: N)
[src]
fn def_attr_writer<N: Into<SymbolId>>(self, name: N) -> Result
[src]
unsafe fn def_attr_writer_unchecked<N: Into<SymbolId>>(self, name: N)
[src]
fn def_attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result
[src]
unsafe fn def_attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N)
[src]
unsafe fn eval(self, args: impl EvalArgs) -> AnyObject
[src]
unsafe fn eval_protected(self, args: impl EvalArgs) -> Result<AnyObject>
[src]
impl Mixin for Module
[src]
fn to_class(self) -> Result<Class, Module>
[src]
fn to_module(self) -> Result<Module, Class>
[src]
fn include(self, module: Module)
[src]
#[must_use]
fn includes(self, module: Module) -> bool
[src]
fn included_modules(self) -> Array<Module>
[src]
fn prepend(self, module: Module)
[src]
fn def_class(self, name: impl Into<SymbolId>) -> Result<Class, DefMixinError>
[src]
fn def_subclass<S: Object>(
self,
superclass: Class<S>,
name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
[src]
self,
superclass: Class<S>,
name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
fn get_class(self, name: impl Into<SymbolId>) -> Option<Class>
[src]
unsafe fn get_class_unchecked(self, name: impl Into<SymbolId>) -> Class
[src]
fn def_module(self, name: impl Into<SymbolId>) -> Result<Module, DefMixinError>
[src]
fn get_module(self, name: impl Into<SymbolId>) -> Option<Module>
[src]
unsafe fn get_module_unchecked(self, name: impl Into<SymbolId>) -> Module
[src]
fn has_const(self, name: impl Into<SymbolId>) -> bool
[src]
fn get_const(self, name: impl Into<SymbolId>) -> AnyObject
[src]
fn set_const(self, name: impl Into<SymbolId>, val: impl Into<AnyObject>)
[src]
fn remove_const(self, name: impl Into<SymbolId>) -> AnyObject
[src]
fn has_class_var(self, var: impl Into<SymbolId>) -> bool
[src]
fn get_class_var(self, var: impl Into<SymbolId>) -> AnyObject
[src]
fn set_class_var<K, V>(self, key: K, val: V) -> Result where
K: Into<SymbolId>,
V: Into<AnyObject>,
[src]
K: Into<SymbolId>,
V: Into<AnyObject>,
unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V) where
K: Into<SymbolId>,
V: Into<AnyObject>,
[src]
K: Into<SymbolId>,
V: Into<AnyObject>,