[][src]Enum mruby::def::EnclosingRubyScope

pub enum EnclosingRubyScope {
    Class {
        spec: Rc<RefCell<Spec>>,
    },
    Module {
        spec: Rc<RefCell<Spec>>,
    },
}

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

Class

Reference to a Ruby Class enclosing scope.

Fields of Class

spec: Rc<RefCell<Spec>>

Shared copy of the underlying class definition.

Module

Reference 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]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl Clone for 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]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

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]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]