pub fn constant<N, V>(&mut self, name: N, value: V) -> Result<(), ContextError>
    where
        N: IntoIterator,
        N::Item: IntoComponent,
        V: ToValue,
    {
        let name = Item::with_item(name);

        if self.constants.contains_key(&name) {
            return Err(ContextError::ConflictingConstantName { name });
        }

        let value = match value.to_value() {
            Ok(v) => v,
            Err(e) => return Err(ContextError::ValueError { error: e }),
        };

        let constant_value = match <ConstValue as FromValue>::from_value(value) {
            Ok(v) => v,
            Err(e) => return Err(ContextError::ValueError { error: e }),
        };

        self.constants.insert(name, constant_value);

        Ok(())
    }
/// Register a constant value, at a crate, module or associated level.
///
/// # Examples
///
/// ```rust
///
/// # fn main() -> runestick::Result<()> {
/// let mut module = runestick::Module::default();
///
/// module.constant(&["TEN"], 10)?; // a global TEN value
/// module.constant(&["MyType", "TEN"], 10)?; // looks like an associated value
///
/// # Ok(()) }
/// ```
Register a constant value, at a crate, module or associated level.
Register a constant value at a crate module or associated level .
pub fn constant<N, V>(&mut self, name: N, value: V) -> Result<(), ContextError>
    where
        N: IntoIterator,
        N::Item: IntoComponent,
        V: ToValue,
    {
        let name = Item::with_item(name);
        if self.constants.contains_key(&name) {
            return Err(ContextError::ConflictingConstantName { name });
        }
        let value = match value.to_value() {
            Ok(v) => v,
            Err(e) => return Err(ContextError::ValueError { error: e }),
        };
        let constant_value = match <ConstValue as FromValue>::from_value(value) {
            Ok(v) => v,
            Err(e) => return Err(ContextError::ValueError { error: e }),
        };
        self.constants.insert(name, constant_value);
        Ok(())
    }
pub fn constant < N , V > ( & mut self , name : N , value : V ) -> Result < ( ) , ContextError > where N : IntoIterator , N :: Item : IntoComponent , V : ToValue , { let name = Item :: with_item ( name ) ; if self . constants . contains_key ( & name ) { return Err ( ContextError :: ConflictingConstantName { name } ) ; } let value = match value . to_value ( ) { Ok ( v ) => v , Err ( e ) => return Err ( ContextError :: ValueError { error : e } ) , } ; let constant_value = match < ConstValue as FromValue > :: from_value ( value ) { Ok ( v ) => v , Err ( e ) => return Err ( ContextError :: ValueError { error : e } ) , } ; self . constants . insert ( name , constant_value ) ; Ok ( ( ) ) }
Register a constant value, at a crate, module or associated level.
Register a constant value at a crate module or associated level .
&mut self
name
N
value
V
&mut self
name
N
value
V
examples
None
fn main() -> runestick::result<()> {
let mut module = runestick::Module::default().

module.constant(&["TEN"], 10)?; // a global TEN value
module.constant(&["MyType", "TEN"], 10)?; // looks like an associated value
let mut module = runestick :: Module :: default () . module . constant ( & [ " TEN " ] 10 ) ? ; // a global TEN value module . constant ( & [ " MyType " " TEN " ] 10 ) ? ; // looks like an associated value
ok(()) }
None