[][src]Struct ralik::Context

pub struct Context(_);

The Context stores all types, free functions and global variables.

While it can be customized to a large extent, it is suggested to start with the default context, which contains working types for the core types:

let context = Context::new();

The default context can then be extended for the specific use case:

// Define a global variable `$` of the Unit type `()`
context.insert_variable("$", Value::new_unit(&context).unwrap());

When starting with an empty context, the core types are not available by default:

let context = Context::new_empty();
Value::new_bool(&context, true).unwrap_err();

Implementations

impl Context[src]

pub fn get_function(
    &self,
    key: &str
) -> Option<fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>>
[src]

pub fn insert_function(
    &self,
    key: impl Into<String>,
    value: fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>
) -> Option<fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>>
[src]

pub fn remove_function(
    &self,
    key: &str
) -> Option<(String, fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>)>
[src]

impl Context[src]

pub fn get_macro(
    &self,
    key: &str
) -> Option<fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>>
[src]

pub fn insert_macro(
    &self,
    key: impl Into<String>,
    value: fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>
) -> Option<fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>>
[src]

pub fn remove_macro(
    &self,
    key: &str
) -> Option<(String, fn(_: &Context, _: &[Value]) -> Result<Value, RuntimeError>)>
[src]

impl Context[src]

pub fn get_type(&self, key: impl AsRef<str>) -> Option<TypeHandle>[src]

pub fn get_unit_type(&self) -> Result<TypeHandle, InvalidTupleType>[src]

pub fn get_bool_type(&self) -> Result<TypeHandle, InvalidBoolType>[src]

pub fn get_char_type(&self) -> Result<TypeHandle, InvalidCharType>[src]

pub fn get_integer_type(&self) -> Result<TypeHandle, InvalidIntegerType>[src]

pub fn get_string_type(&self) -> Result<TypeHandle, InvalidStringType>[src]

pub fn get_tuple_type(
    &self,
    element_type_names: impl Iterator<Item = impl AsRef<str> + Debug> + Clone
) -> Result<TypeHandle, InvalidTupleType>
[src]

pub fn get_array_type(
    &self,
    element_type_name: &str
) -> Result<TypeHandle, InvalidArrayType>
[src]

pub fn get_option_type(
    &self,
    element_type_name: &str
) -> Result<TypeHandle, InvalidArrayType>
[src]

pub fn insert_type(&self, value: impl Type + 'static) -> TypeHandle[src]

impl Context[src]

pub fn get_variable(&self, key: &str) -> Option<Value>[src]

pub fn insert_variable(
    &self,
    key: impl Into<String>,
    value: impl Into<Value>
) -> Option<Value>
[src]

pub fn remove_variable(&self, key: &str) -> Option<(String, Value)>[src]

impl Context[src]

pub fn new() -> Self[src]

pub fn new_empty() -> Self[src]

Trait Implementations

impl Clone for Context[src]

impl Debug for Context[src]

impl Default for Context[src]

Auto Trait Implementations

impl RefUnwindSafe for Context

impl !Send for Context

impl !Sync for Context

impl Unpin for Context

impl UnwindSafe for Context

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.