pub struct ModuleConstantBuilder<'a, N, V> { /* private fields */ }
Expand description
Raw function builder as returned by Module::raw_function
.
This allows for building a function regularly with
ModuleConstantBuilder::build
or statically associate the function with a
type through ModuleConstantBuilder::build_associated::<T>
.
Implementations§
Source§impl<'a, N, V> ModuleConstantBuilder<'a, N, V>
impl<'a, N, V> ModuleConstantBuilder<'a, N, V>
Sourcepub fn build(self) -> Result<ItemMut<'a>, ContextError>where
N: IntoComponent,
pub fn build(self) -> Result<ItemMut<'a>, ContextError>where
N: IntoComponent,
Add the free constant directly to the module.
§Examples
use rune::{Any, Module};
use rune::runtime::VmResult;
let mut m = Module::with_item(["module"])?;
m.constant("NAME", "Hello World").build()?;
Sourcepub fn build_associated<T>(self) -> Result<ItemMut<'a>, ContextError>where
T: TypeOf,
N: ToInstance,
pub fn build_associated<T>(self) -> Result<ItemMut<'a>, ContextError>where
T: TypeOf,
N: ToInstance,
Build a constant that is associated with the static type T
.
§Errors
This function call will cause an error in Context::install
if the
type we’re associating it with has not been registered.
use rune::{Any, Context, Module};
#[derive(Any)]
struct Thing;
let mut m = Module::default();
m.constant("CONSTANT", "Hello World").build_associated::<Thing>()?;
let mut c = Context::default();
assert!(c.install(m).is_err());
§Examples
use rune::{docstring, Any, Module};
let mut module = Module::default();
#[derive(Any)]
struct Thing;
module.constant("TEN", 10)
.build_associated::<Thing>()?
.docs(docstring! {
/// Ten which is an associated constant.
});
Auto Trait Implementations§
impl<'a, N, V> Freeze for ModuleConstantBuilder<'a, N, V>
impl<'a, N, V> !RefUnwindSafe for ModuleConstantBuilder<'a, N, V>
impl<'a, N, V> Send for ModuleConstantBuilder<'a, N, V>
impl<'a, N, V> Sync for ModuleConstantBuilder<'a, N, V>
impl<'a, N, V> Unpin for ModuleConstantBuilder<'a, N, V>
impl<'a, N, V> !UnwindSafe for ModuleConstantBuilder<'a, N, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more