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
sourceimpl 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
sourceimpl Clone for EnclosingRubyScope
impl Clone for EnclosingRubyScope
sourcefn clone(&self) -> EnclosingRubyScope
fn clone(&self) -> EnclosingRubyScope
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for EnclosingRubyScope
impl Debug for EnclosingRubyScope
sourceimpl Hash for EnclosingRubyScope
impl Hash for EnclosingRubyScope
sourceimpl PartialEq<EnclosingRubyScope> for EnclosingRubyScope
impl PartialEq<EnclosingRubyScope> for EnclosingRubyScope
sourcefn eq(&self, other: &EnclosingRubyScope) -> bool
fn eq(&self, other: &EnclosingRubyScope) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &EnclosingRubyScope) -> bool
fn ne(&self, other: &EnclosingRubyScope) -> bool
This method tests for !=
.
impl Eq for EnclosingRubyScope
impl StructuralEq for EnclosingRubyScope
impl StructuralPartialEq for EnclosingRubyScope
Auto Trait Implementations
impl RefUnwindSafe for EnclosingRubyScope
impl Send for EnclosingRubyScope
impl Sync for EnclosingRubyScope
impl Unpin for EnclosingRubyScope
impl UnwindSafe for EnclosingRubyScope
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more