Skip to main content

PackageReg

Struct PackageReg 

Source
pub struct PackageReg<'r, P: Package> { /* private fields */ }
Expand description

A typed registration entry passed to Package::register.

Registration failures (the first half of a name is not P::NAME, double registration of the same name, and so on) are remembered (the first one), and Registry::package returns it as Err (the registry is then unchanged).

Implementations§

Source§

impl<'r, P: Package> PackageReg<'r, P>

Source

pub fn alias(&mut self, old: &str) -> &mut Self

Registers an old name (alias) of the command registered just before (section 2.2 of spec/host/02-registry.md). The old name is namespace.name, and may be in another package’s namespace.

Source

pub fn doc(&mut self, text: &str) -> &mut Self

Adds a description to the command, variable or type registered just before.

Source

pub fn param_names(&mut self, names: &[&str]) -> &mut Self

Names the parameters of the command registered just before. The count must be the same as the parameters.

Source

pub fn defaults(&mut self, defaults: &[(&str, Value)]) -> &mut Self

Adds default values to the parameters of the command registered just before (names are those given with param_names; Registry::param_defaults).

Source

pub fn text_param(&mut self, index: usize) -> &mut Self

Makes parameter index (str) of the stop command registered just before a body that text tables can translate (such as input prompts). It is replaced with that line’s key only when the script writes it as a string literal and the line has a stable ID.

Source

pub fn ty<T: YomiDecl>(&mut self) -> &mut Self

Registers a struct or enum (a type with #[derive(YomiType)]). The namespace must be the package’s name (InvalidName otherwise). Register the types it uses first.

Source

pub fn effect<Args, R, F: EffectFn<P, Args, R> + Send + Sync + 'static>( &mut self, name: &str, f: F, ) -> &mut Self

Registers an effect command. The function is Fn(&mut Ctx<P>, args...) -> R (R is (), a type usable in scripts, or Result<that, CommandError>). Parameter and return types are derived from the function. The function is Send + Sync (so the VM can run on other threads).

Source

pub fn query<Args, R, F: QueryFn<P, Args, R> + Send + Sync + 'static>( &mut self, name: &str, f: F, ) -> &mut Self

Registers a query command. The function is Fn(&Ctx<P>, args...) -> R. It does not change state and returns the same value for the same state. The return value cannot be (). The function is Send + Sync.

Source

pub fn stop<A: YomiArgs, R: YomiType>(&mut self, name: &str) -> &mut Self

Registers a stop command by declaring only its types (the host does the work).

Source

pub fn stop_checked<A, R, F>(&mut self, name: &str, check: F) -> &mut Self
where A: FromArgs + 'static, R: YomiType, F: Fn(A) -> Result<(), CommandError> + Send + Sync + 'static,

Registers a stop command with validation. check is called with the evaluated arguments before the VM returns the stop notification. If it is Err, it does not stop and becomes a runtime error (the VM adds the position). check is Send + Sync.

Source

pub fn stop_validated<A, R, F, G>( &mut self, name: &str, check_args: F, check_return: G, ) -> &mut Self
where A: FromArgs + 'static, R: FromValue + 'static, F: Fn(&A) -> Result<(), CommandError> + Send + Sync + 'static, G: Fn(&A, &R) -> Result<(), CommandError> + Send + Sync + 'static,

Registers a stop command with checks of arguments and return values.

  • check_args is the same as check of stop_checked (called with the evaluated arguments before stopping; if Err, it does not stop and becomes a runtime error).
  • check_return is called with the arguments at the stop and the returned value, after the type of the value the host returned with Input::Return has matched and before the value is passed to the script. If Err, resume returns a runtime error (the VM adds the position; the VM is left in the state after a runtime error and can be restored from a snapshot with restore).
  • Both functions are Send + Sync.
Source

pub fn var<T: YomiType + IntoValue>( &mut self, name: &str, kind: Kind, initial: T, ) -> VarHandle<'_>

Registers a variable declared by the host. The name is P::NAME.variable. .read_only() makes it impossible for scripts to assign to it. The type is one of int, float, bool, str.

Auto Trait Implementations§

§

impl<'r, P> !RefUnwindSafe for PackageReg<'r, P>

§

impl<'r, P> !UnwindSafe for PackageReg<'r, P>

§

impl<'r, P> Forget for PackageReg<'r, P>

§

impl<'r, P> Freeze for PackageReg<'r, P>
where PhantomData<fn() -> P>: Freeze,

§

impl<'r, P> Move for PackageReg<'r, P>

§

impl<'r, P> Send for PackageReg<'r, P>
where PhantomData<fn() -> P>: Send,

§

impl<'r, P> Sync for PackageReg<'r, P>
where PhantomData<fn() -> P>: Sync,

§

impl<'r, P> Unpin for PackageReg<'r, P>
where PhantomData<fn() -> P>: Unpin,

§

impl<'r, P> UnsafeUnpin for PackageReg<'r, P>
where PhantomData<fn() -> P>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.