pub enum EnclosingRubyScope {
Class(ClassScope),
Module(ModuleScope),
}Expand description
Typesafe wrapper for the RClass * of the enclosing scope for an mruby
Module or Class.
In Ruby, classes and modules can be defined inside another class or module.
mruby only supports resolving RClass pointers relative to an enclosing
scope. This can be the top level with mrb_class_get and
mrb_module_get or it can be under another class with
mrb_class_get_under or module with mrb_module_get_under.
Because there is no C API to resolve class and module names directly, each
class-like holds a reference to its enclosing scope so it can recursively
resolve its enclosing RClass *.
Variants§
Class(ClassScope)
Reference to a Ruby Class enclosing scope.
Module(ModuleScope)
Reference to a Ruby Module enclosing scope.
Implementations§
Source§impl EnclosingRubyScope
impl EnclosingRubyScope
Sourcepub fn class(spec: &Spec) -> Self
pub fn class(spec: &Spec) -> Self
Factory for EnclosingRubyScope::Class that clones a class::Spec.
This function is useful when extracting an enclosing scope from the class registry.
Sourcepub fn module(spec: &Spec) -> Self
pub fn module(spec: &Spec) -> Self
Factory for EnclosingRubyScope::Module that clones a
module::Spec.
This function is useful when extracting an enclosing scope from the module registry.
Sourcepub unsafe fn rclass(&self, mrb: *mut mrb_state) -> Option<NonNull<RClass>>
pub unsafe fn rclass(&self, mrb: *mut mrb_state) -> Option<NonNull<RClass>>
Resolve the RClass * of the wrapped class or module.
Return None if the class-like has no EnclosingRubyScope.
The current implementation results in recursive calls to this function for each enclosing scope.
§Safety
This function must be called within an Artichoke::with_ffi_boundary
closure because the FFI APIs called in this function may require access
to the Artichoke State.
Sourcepub fn fqname(&self) -> Cow<'_, str>
pub fn fqname(&self) -> Cow<'_, str>
Get the fully-qualified name of the wrapped class or module.
For example, in the following Ruby code, C has a fully-qualified name
of A::B::C.
module A
class B
module C
CONST = 1
end
end
endThe current implementation results in recursive calls to this function for each enclosing scope.
Trait Implementations§
Source§impl Clone for EnclosingRubyScope
impl Clone for EnclosingRubyScope
Source§fn clone(&self) -> EnclosingRubyScope
fn clone(&self) -> EnclosingRubyScope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more