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>
impl<'r, P: Package> PackageReg<'r, P>
Sourcepub fn alias(&mut self, old: &str) -> &mut Self
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.
Sourcepub fn doc(&mut self, text: &str) -> &mut Self
pub fn doc(&mut self, text: &str) -> &mut Self
Adds a description to the command, variable or type registered just before.
Sourcepub fn param_names(&mut self, names: &[&str]) -> &mut Self
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.
Sourcepub fn defaults(&mut self, defaults: &[(&str, Value)]) -> &mut Self
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).
Sourcepub fn text_param(&mut self, index: usize) -> &mut Self
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.
Sourcepub fn ty<T: YomiDecl>(&mut self) -> &mut Self
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.
Sourcepub fn effect<Args, R, F: EffectFn<P, Args, R> + Send + Sync + 'static>(
&mut self,
name: &str,
f: F,
) -> &mut Self
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).
Sourcepub fn query<Args, R, F: QueryFn<P, Args, R> + Send + Sync + 'static>(
&mut self,
name: &str,
f: F,
) -> &mut Self
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.
Sourcepub fn stop<A: YomiArgs, R: YomiType>(&mut self, name: &str) -> &mut Self
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).
Sourcepub fn stop_checked<A, R, F>(&mut self, name: &str, check: F) -> &mut Self
pub fn stop_checked<A, R, F>(&mut self, name: &str, check: F) -> &mut Self
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.
Sourcepub fn stop_validated<A, R, F, G>(
&mut self,
name: &str,
check_args: F,
check_return: G,
) -> &mut Self
pub fn stop_validated<A, R, F, G>( &mut self, name: &str, check_args: F, check_return: G, ) -> &mut Self
Registers a stop command with checks of arguments and return values.
check_argsis the same ascheckofstop_checked(called with the evaluated arguments before stopping; ifErr, it does not stop and becomes a runtime error).check_returnis called with the arguments at the stop and the returned value, after the type of the value the host returned withInput::Returnhas matched and before the value is passed to the script. IfErr,resumereturns 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 withrestore).- Both functions are
Send + Sync.