artichoke_core/constant.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
//! Define constants on an interpreter.
//!
//! Constants can be an arbitrary Ruby value. Constants can be defined globally,
//! on a class, or on a module.
use crate::value::Value;
/// Define constants on an interpreter.
///
/// Constants can be an arbitrary Ruby value. Constants can be defined globally,
/// on a class, or on a module.
pub trait DefineConstant {
/// Concrete type for Ruby values.
type Value: Value;
/// Concrete error type for fallible operations.
type Error;
/// Define a global constant.
///
/// # Errors
///
/// If the given constant name is not valid, an error is returned.
///
/// If the interpreter cannot define the constant, an error is returned.
fn define_global_constant(&mut self, constant: &str, value: Self::Value) -> Result<(), Self::Error>;
/// Define a class constant.
///
/// The class is specified by the type parameter `T`.
///
/// # Errors
///
/// If the class named by type `T` is not defined, an error is returned.
///
/// If the given constant name is not valid, an error is returned.
///
/// If the interpreter cannot define the constant, an error is returned.
fn define_class_constant<T>(&mut self, constant: &str, value: Self::Value) -> Result<(), Self::Error>
where
T: 'static;
/// Define a module constant.
///
/// The class is specified by the type parameter `T`.
///
/// # Errors
///
/// If the module named by type `T` is not defined, an error is returned.
///
/// If the given constant name is not valid, an error is returned.
///
/// If the interpreter cannot define the constant, an error is returned.
fn define_module_constant<T>(&mut self, constant: &str, value: Self::Value) -> Result<(), Self::Error>
where
T: 'static;
}