[][src]Trait rosy::Mixin

pub trait Mixin: Object + Sealed {
    fn to_class(self) -> Result<Class, Module>;
fn to_module(self) -> Result<Module, Class>; fn include(self, module: Module) { ... }
#[must_use]
fn includes(self, module: Module) -> bool { ... }
fn included_modules(self) -> Array<Module> { ... }
fn prepend(self, module: Module) { ... }
fn def_class(
        self,
        name: impl Into<SymbolId>
    ) -> Result<Class, DefMixinError> { ... }
fn def_subclass(
        self,
        superclass: Class,
        name: impl Into<SymbolId>
    ) -> Result<Class, DefMixinError> { ... }
fn get_class(self, name: impl Into<SymbolId>) -> Option<Class> { ... }
unsafe fn get_class_unchecked(self, name: impl Into<SymbolId>) -> Class { ... }
fn def_module(
        self,
        name: impl Into<SymbolId>
    ) -> Result<Module, DefMixinError> { ... }
fn get_module(self, name: impl Into<SymbolId>) -> Option<Module> { ... }
unsafe fn get_module_unchecked(self, name: impl Into<SymbolId>) -> Module { ... }
fn has_const(self, name: impl Into<SymbolId>) -> bool { ... }
fn get_const(self, name: impl Into<SymbolId>) -> AnyObject { ... }
fn set_const(self, name: impl Into<SymbolId>, val: impl Object) { ... }
fn remove_const(self, name: impl Into<SymbolId>) -> AnyObject { ... }
fn has_class_var(self, var: impl Into<SymbolId>) -> bool { ... }
fn get_class_var(self, var: impl Into<SymbolId>) -> AnyObject { ... }
fn set_class_var<K, V>(self, key: K, val: V) -> Result<()>
    where
        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>
, { ... }
fn attr_reader<N: Into<SymbolId>>(self, name: N) -> Result { ... }
unsafe fn attr_reader_unchecked<N: Into<SymbolId>>(self, name: N) { ... }
fn attr_writer<N: Into<SymbolId>>(self, name: N) -> Result { ... }
unsafe fn attr_writer_unchecked<N: Into<SymbolId>>(self, name: N) { ... }
fn attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result { ... }
unsafe fn attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N) { ... }
unsafe fn eval_unchecked(self, args: impl EvalArgs) -> AnyObject { ... }
fn eval(self, args: impl EvalArgs) -> Result<AnyObject> { ... } }

A type that supports mixins (see Class and Module).

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.

Loading content...

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(
    self,
    superclass: Class,
    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 a Class

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 a Module

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 Object)

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>, 

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>, 

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 attr_reader<N: Into<SymbolId>>(self, name: N) -> Result

Defines an read-only attribute on self with name.

unsafe fn 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 attr_writer<N: Into<SymbolId>>(self, name: N) -> Result

Defines a write-only attribute on self with name.

unsafe fn 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 attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result

Defines a read-write attribute on self with name.

unsafe fn 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_unchecked(self, args: impl EvalArgs) -> AnyObject

Evaluates args in the context of self.

See the docs for EvalArgs for more info.

Safety

An exception may be raised by the code or by args being invalid.

fn eval(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.

Loading content...

Implementors

impl Mixin for 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(
    self,
    superclass: Class,
    name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
[src]

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 Object)[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]

unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V) where
    K: Into<SymbolId>,
    V: Into<AnyObject>, 
[src]

fn attr_reader<N: Into<SymbolId>>(self, name: N) -> Result[src]

unsafe fn attr_reader_unchecked<N: Into<SymbolId>>(self, name: N)[src]

fn attr_writer<N: Into<SymbolId>>(self, name: N) -> Result[src]

unsafe fn attr_writer_unchecked<N: Into<SymbolId>>(self, name: N)[src]

fn attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result[src]

unsafe fn attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N)[src]

unsafe fn eval_unchecked(self, args: impl EvalArgs) -> AnyObject[src]

fn eval(self, args: impl EvalArgs) -> Result<AnyObject>[src]

impl Mixin for Module[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(
    self,
    superclass: Class,
    name: impl Into<SymbolId>
) -> Result<Class, DefMixinError>
[src]

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 Object)[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]

unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V) where
    K: Into<SymbolId>,
    V: Into<AnyObject>, 
[src]

fn attr_reader<N: Into<SymbolId>>(self, name: N) -> Result[src]

unsafe fn attr_reader_unchecked<N: Into<SymbolId>>(self, name: N)[src]

fn attr_writer<N: Into<SymbolId>>(self, name: N) -> Result[src]

unsafe fn attr_writer_unchecked<N: Into<SymbolId>>(self, name: N)[src]

fn attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result[src]

unsafe fn attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N)[src]

unsafe fn eval_unchecked(self, args: impl EvalArgs) -> AnyObject[src]

fn eval(self, args: impl EvalArgs) -> Result<AnyObject>[src]

Loading content...