pub struct Module(/* private fields */);
Expand description
An instance of Ruby’s Module
type.
Implementations§
Source§impl Module
impl Module
Sourcepub unsafe fn extend_unchecked(self, object: impl Object)
pub unsafe fn extend_unchecked(self, object: impl Object)
Extends object
with the contents of self
.
§Safety
The caller must ensure that self
is not frozen or else a FrozenError
exception will be raised.
Sourcepub fn def(name: impl Into<SymbolId>) -> Result<Self, DefMixinError>
pub fn def(name: impl Into<SymbolId>) -> Result<Self, DefMixinError>
Defines a new top-level module with name
.
§Examples
Defining a new module is straightforward:
let my_mod = rosy::Module::def("MyMod").unwrap();
Attempting to define an existing module will result in an error:
use rosy::Module;
let math = Module::def("Math").unwrap_err().existing_object();
assert_eq!(Module::math(), math.unwrap());
Sourcepub fn get(name: impl Into<SymbolId>) -> Option<Self>
pub fn get(name: impl Into<SymbolId>) -> Option<Self>
Retrieves an existing top-level Module
defined by name
.
Sourcepub unsafe fn get_unchecked(name: impl Into<SymbolId>) -> Self
pub unsafe fn get_unchecked(name: impl Into<SymbolId>) -> Self
Retrieves an existing top-level Module
defined by name
.
§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
Sourcepub fn get_or_def(name: impl Into<SymbolId>) -> Result<Self, DefMixinError>
pub fn get_or_def(name: impl Into<SymbolId>) -> Result<Self, DefMixinError>
Retrieves an existing top-level Module
defined by name
or defines
one if it doesn’t exist.
Source§impl Module
Built-in modules.
impl Module
Built-in modules.
Sourcepub fn comparable() -> Self
pub fn comparable() -> Self
The Comparable
module.
Sourcepub fn enumerable() -> Self
pub fn enumerable() -> Self
The Enumerable
module.
Sourcepub fn wait_readable() -> Self
pub fn wait_readable() -> Self
The WaitReadable
module.
Sourcepub fn wait_writable() -> Self
pub fn wait_writable() -> Self
The WaitWritable
module.
Trait Implementations§
Source§impl Mixin for Module
impl Mixin for Module
Source§fn to_class(self) -> Result<Class, Module>
fn to_class(self) -> Result<Class, Module>
Returns
self
as a Class
if it is one or a Module
otherwise.Source§fn to_module(self) -> Result<Module, Class>
fn to_module(self) -> Result<Module, Class>
Returns
self
as a Module
if it is one or a Class
otherwise.Source§fn included_modules(self) -> Array<Module>
fn included_modules(self) -> Array<Module>
Returns an array of the modules included in
self
.Source§fn def_class(self, name: impl Into<SymbolId>) -> Result<Class, DefMixinError>
fn def_class(self, name: impl Into<SymbolId>) -> Result<Class, DefMixinError>
Defines a new class under
self
with name
.Source§fn def_subclass<S: Object>(
self,
superclass: Class<S>,
name: impl Into<SymbolId>,
) -> Result<Class, DefMixinError>
fn def_subclass<S: Object>( self, superclass: Class<S>, name: impl Into<SymbolId>, ) -> Result<Class, DefMixinError>
Defines a new subclass of
superclass
under self
with name
.Source§fn get_class(self, name: impl Into<SymbolId>) -> Option<Class>
fn get_class(self, name: impl Into<SymbolId>) -> Option<Class>
Returns the existing
Class
with name
in self
.Source§fn def_module(self, name: impl Into<SymbolId>) -> Result<Module, DefMixinError>
fn def_module(self, name: impl Into<SymbolId>) -> Result<Module, DefMixinError>
Defines a new module under
self
with name
.Source§fn get_module(self, name: impl Into<SymbolId>) -> Option<Module>
fn get_module(self, name: impl Into<SymbolId>) -> Option<Module>
Returns the existing
Module
with name
in self
.Source§fn has_const(self, name: impl Into<SymbolId>) -> bool
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
.Source§fn set_const(self, name: impl Into<SymbolId>, val: impl Into<AnyObject>)
fn set_const(self, name: impl Into<SymbolId>, val: impl Into<AnyObject>)
Sets the value a constant for
name
in self
to val
.Source§fn remove_const(self, name: impl Into<SymbolId>) -> AnyObject
fn remove_const(self, name: impl Into<SymbolId>) -> AnyObject
Removes the constant value for
name
, returning it. Read moreSource§fn has_class_var(self, var: impl Into<SymbolId>) -> bool
fn has_class_var(self, var: impl Into<SymbolId>) -> bool
Returns whether the class-level
var
is defined in self
.Source§fn set_class_var<K, V>(self, key: K, val: V) -> Result
fn set_class_var<K, V>(self, key: K, val: V) -> Result
Sets the class-level
var
in self
to val
.Source§unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V)
unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V)
Source§fn def_attr_reader<N: Into<SymbolId>>(self, name: N) -> Result
fn def_attr_reader<N: Into<SymbolId>>(self, name: N) -> Result
Defines an read-only attribute on
self
with name
.Source§unsafe fn def_attr_reader_unchecked<N: Into<SymbolId>>(self, name: N)
unsafe fn def_attr_reader_unchecked<N: Into<SymbolId>>(self, name: N)
Source§fn def_attr_writer<N: Into<SymbolId>>(self, name: N) -> Result
fn def_attr_writer<N: Into<SymbolId>>(self, name: N) -> Result
Defines a write-only attribute on
self
with name
.Source§unsafe fn def_attr_writer_unchecked<N: Into<SymbolId>>(self, name: N)
unsafe fn def_attr_writer_unchecked<N: Into<SymbolId>>(self, name: N)
Source§fn def_attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result
fn def_attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result
Defines a read-write attribute on
self
with name
.Source§unsafe fn def_attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N)
unsafe fn def_attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N)
Source§impl Object for Module
impl Object for Module
Source§fn unique_id() -> Option<u128>
fn unique_id() -> Option<u128>
Returns a unique identifier for an object type to facilitate casting. Read more
Source§fn cast<A: Object>(obj: A) -> Option<Self>
fn cast<A: Object>(obj: A) -> Option<Self>
Attempts to create an instance by casting
obj
. Read moreSource§unsafe fn from_raw(raw: usize) -> Self
unsafe fn from_raw(raw: usize) -> Self
Creates a new object from
raw
without checking. Read moreSource§unsafe fn cast_unchecked(obj: impl Object) -> Self
unsafe fn cast_unchecked(obj: impl Object) -> Self
Casts
obj
to Self
without checking its type.Source§fn into_any_object(self) -> AnyObject
fn into_any_object(self) -> AnyObject
Returns
self
as an AnyObject
.Source§fn as_any_object(&self) -> &AnyObject
fn as_any_object(&self) -> &AnyObject
Returns a reference to
self
as an AnyObject
.Source§fn as_any_slice(&self) -> &[AnyObject]
fn as_any_slice(&self) -> &[AnyObject]
Returns
self
as a reference to a single-element slice.Source§unsafe fn as_unchecked<O: Object>(&self) -> &O
unsafe fn as_unchecked<O: Object>(&self) -> &O
Casts
self
to O
without checking whether it is one.Source§unsafe fn into_unchecked<O: Object>(self) -> O
unsafe fn into_unchecked<O: Object>(self) -> O
Converts
self
to O
without checking whether it is one.Source§fn singleton_class(self) -> Class<Self>
fn singleton_class(self) -> Class<Self>
Source§unsafe fn force_recycle(self)
unsafe fn force_recycle(self)
Forces the garbage collector to free the contents of
self
. Read moreSource§fn def_singleton_method<N, F>(self, name: N, f: F) -> Result
fn def_singleton_method<N, F>(self, name: N, f: F) -> Result
Defines a method for
name
on the singleton class of self
that calls
f
when invoked.Source§unsafe fn def_singleton_method_unchecked<N, F>(self, name: N, f: F)
unsafe fn def_singleton_method_unchecked<N, F>(self, name: N, f: F)
Source§unsafe fn call_with_protected(
self,
method: impl Into<SymbolId>,
args: &[impl Object],
) -> Result<AnyObject>
unsafe fn call_with_protected( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> Result<AnyObject>
Source§unsafe fn call_public_with(
self,
method: impl Into<SymbolId>,
args: &[impl Object],
) -> AnyObject
unsafe fn call_public_with( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> AnyObject
Source§unsafe fn call_public_with_protected(
self,
method: impl Into<SymbolId>,
args: &[impl Object],
) -> Result<AnyObject>
unsafe fn call_public_with_protected( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> Result<AnyObject>
Calls the public
method
on self
with args
and returns its output,
or an exception if one is raised. Read moreSource§fn is_eql<O: Object>(self, other: &O) -> bool
fn is_eql<O: Object>(self, other: &O) -> bool
Returns whether
self
is equal to other
in terms of the eql?
method.Source§fn get_attr<N: Into<SymbolId>>(self, name: N) -> AnyObject
fn get_attr<N: Into<SymbolId>>(self, name: N) -> AnyObject
Returns the value for the attribute of
self
associated with name
.impl Copy for Module
impl Eq for Module
Auto Trait Implementations§
impl Freeze for Module
impl RefUnwindSafe for Module
impl !Send for Module
impl !Sync for Module
impl Unpin for Module
impl UnwindSafe for Module
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
Mutably borrows from an owned value. Read more