artichoke_backend::prelude

Trait ModuleRegistry

Source
pub trait ModuleRegistry {
    type Value;
    type Error;
    type Spec: 'static;

    // Required methods
    fn def_module<T>(&mut self, spec: Self::Spec) -> Result<(), Self::Error>
       where T: Any;
    fn module_spec<T>(&self) -> Result<Option<&Self::Spec>, Self::Error>
       where T: Any;
    fn module_of<T>(&mut self) -> Result<Option<Self::Value>, Self::Error>
       where T: Any;

    // Provided method
    fn is_module_defined<T>(&self) -> bool
       where T: Any { ... }
}
Expand description

Define and store module specs on an interpreter.

A module spec is a static set of information the interpreter requires to define a Ruby Module object.

Required Associated Types§

Source

type Value

Concrete value type for boxed Ruby values.

Source

type Error

Concrete error type for errors encountered when manipulating the module registry.

Source

type Spec: 'static

Type representing a module specification.

Required Methods§

Source

fn def_module<T>(&mut self, spec: Self::Spec) -> Result<(), Self::Error>
where T: Any,

Create a module definition bound to a Rust type T.

Module definitions have the same lifetime as the interpreter.

§Errors

If the module registry state is inaccessible, an error is returned.

Source

fn module_spec<T>(&self) -> Result<Option<&Self::Spec>, Self::Error>
where T: Any,

Retrieve a module definition from the interpreter bound to Rust type T.

This function returns None if type T has not had a module spec registered for it using ModuleRegistry::def_module.

§Errors

If the module registry state is inaccessible, an error is returned.

Source

fn module_of<T>(&mut self) -> Result<Option<Self::Value>, Self::Error>
where T: Any,

Retrieve a boxed Ruby value containing a Module object for the Module bound to Rust type T.

If the interpreter cannot find or load a module associated with T, Ok(None) is returned.

§Errors

If the module registry state is inaccessible, an error is returned.

Provided Methods§

Source

fn is_module_defined<T>(&self) -> bool
where T: Any,

Retrieve whether a module definition exists from the interpreter bound to Rust type T

If the interpreter cannot find or load a module associated with T, Ok(None) is returned.

§Errors

If the module registry state is inaccessible, an error is returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§