[−][src]Enum mruby::def::EnclosingRubyScope
Typesafe wrapper for the RClass * of the enclosing scope
for an mruby Module or Class.
In Ruby, classes and modules can be defined inside of 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
ClassLike with mrb_class_get_under and
mrb_module_get_under.
Because there is no C API to resolve class and module names directly, each
ClassLike holds a reference to its enclosing scope so it can recursively
resolve its enclosing RClass *.
Variants
ClassReference to a Ruby Class enclosing scope.
Fields of Class
spec: Rc<RefCell<Spec>>Shared copy of the underlying class definition.
ModuleReference to a Ruby Module enclosing scope.
Fields of Module
spec: Rc<RefCell<Spec>>Shared copy of the underlying module definition.
Methods
impl EnclosingRubyScope[src]
pub fn class(spec: Rc<RefCell<Spec>>) -> Self[src]
Factory for EnclosingRubyScope::Class that clones an Rc smart
pointer wrapped class::Spec.
This function is useful when extracting an enclosing scope from the class registry:
use mruby::def::EnclosingRubyScope; struct Fixnum; struct Inner; let interp = mruby::interpreter().expect("mrb init"); let mut api = interp.borrow_mut(); if let Some(scope) = api.class_spec::<Fixnum>().map(EnclosingRubyScope::class) { api.def_class::<Inner>("Inner", Some(scope), None); }
Which defines this Ruby Class:
class Fixnum
class Inner
end
end
pub fn module(spec: Rc<RefCell<Spec>>) -> Self[src]
Factory for EnclosingRubyScope::Module that clones an Rc smart
pointer wrapped module::Spec.
This function is useful when extracting an enclosing scope from the module registry:
use mruby::def::EnclosingRubyScope; struct Kernel; struct Inner; let interp = mruby::interpreter().expect("mrb init"); let mut api = interp.borrow_mut(); if let Some(scope) = api.module_spec::<Kernel>().map(EnclosingRubyScope::module) { api.def_class::<Inner>("Inner", Some(scope), None); }
Which defines this Ruby Class:
module Kernel
class Inner
end
end
pub fn rclass(&self, interp: &Mrb) -> Option<*mut RClass>[src]
Resolve the RClass * of the wrapped ClassLike.
Return None if the ClassLike has no EnclosingRubyScope.
The current implemention results in recursive calls to this function for each enclosing scope.
pub fn fqname(&self) -> String[src]
Get the fully qualified name of the wrapped ClassLike.
For example, in the following Ruby code, C has an fqname of A::B::C.
module A
class B
module C
CONST = 1
end
end
end
The current implemention results in recursive calls to this function for each enclosing scope.
Trait Implementations
impl Eq for EnclosingRubyScope[src]
impl PartialEq<EnclosingRubyScope> for EnclosingRubyScope[src]
fn eq(&self, other: &Self) -> bool[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl Clone for EnclosingRubyScope[src]
fn clone(&self) -> EnclosingRubyScope[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Debug for EnclosingRubyScope[src]
impl Hash for EnclosingRubyScope[src]
Auto Trait Implementations
impl !Send for EnclosingRubyScope
impl Unpin for EnclosingRubyScope
impl !Sync for EnclosingRubyScope
impl !UnwindSafe for EnclosingRubyScope
impl !RefUnwindSafe for EnclosingRubyScope
Blanket Implementations
impl<T> From<T> for T[src]
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,