artichoke_core::globals

Trait Globals

Source
pub trait Globals {
    type Value: Value;
    type Error;

    // Required methods
    fn set_global_variable<T>(
        &mut self,
        name: T,
        value: &Self::Value,
    ) -> Result<(), Self::Error>
       where T: Into<Cow<'static, [u8]>>;
    fn unset_global_variable<T>(&mut self, name: T) -> Result<(), Self::Error>
       where T: Into<Cow<'static, [u8]>>;
    fn get_global_variable<T>(
        &mut self,
        name: T,
    ) -> Result<Option<Self::Value>, Self::Error>
       where T: Into<Cow<'static, [u8]>>;
}
Expand description

Get and set global variables on an interpreter.

Global variables can be an arbitrary Ruby value. Variable names must start with $.

Required Associated Types§

Source

type Value: Value

Concrete value type for global variables.

Source

type Error

Concrete error type for failures manipulating global variables.

Required Methods§

Source

fn set_global_variable<T>( &mut self, name: T, value: &Self::Value, ) -> Result<(), Self::Error>
where T: Into<Cow<'static, [u8]>>,

Set global variable pointed to by name to the given Ruby value.

§Errors

If the name is not a valid global name, an error is returned.

If there is insufficient capacity in the global storage, an error is returned.

Source

fn unset_global_variable<T>(&mut self, name: T) -> Result<(), Self::Error>
where T: Into<Cow<'static, [u8]>>,

Unset global variable pointed to by name.

Unsetting a global variable removes the name from the global storage table. Unset globals resolve to nil in the Ruby VM.

Unsetting a global that is currently unset is a no-op.

§Errors

If the name is not a valid global name, an error is returned.

Source

fn get_global_variable<T>( &mut self, name: T, ) -> Result<Option<Self::Value>, Self::Error>
where T: Into<Cow<'static, [u8]>>,

Get the Ruby value stored in the global variable pointed to by name.

§Compatibility Notes

Getting a global that is currently may return Ok(None) even through a non-existent global resolves to nil in the Ruby VM. Consult the documentation on implementations of this trait for implementation-defined behavior.

§Errors

If the name is not a valid global name, 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§