Enum artichoke_backend::def::EnclosingRubyScope
source · 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
end
The 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 moresource§impl Debug for EnclosingRubyScope
impl Debug for EnclosingRubyScope
source§impl Hash for EnclosingRubyScope
impl Hash for EnclosingRubyScope
source§impl PartialEq for EnclosingRubyScope
impl PartialEq for EnclosingRubyScope
impl Eq for EnclosingRubyScope
impl StructuralPartialEq for EnclosingRubyScope
Auto Trait Implementations§
impl Freeze for EnclosingRubyScope
impl RefUnwindSafe for EnclosingRubyScope
impl Send for EnclosingRubyScope
impl Sync for EnclosingRubyScope
impl Unpin for EnclosingRubyScope
impl UnwindSafe for EnclosingRubyScope
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)