Skip to main content

RegistrationContext

Struct RegistrationContext 

pub struct RegistrationContext { /* private fields */ }
Expand description

A registration phase’s view. Declarations go on the hook’s event; there is no world, handle constructor, transaction or game Host at this point.

Every registration hook (register, component_types, blocks, items, standalone_models and the other Register* hooks) reads the same frozen view, captured once before the first of them runs, so an answer never depends on dispatch order or on which hook asks:

  • mods: the loaded packages.
  • registry: the built-in registries, as registries.json lists them. Entries that mods declare during registration are not in it; a mod already has its own declarations on its event or registrar.
  • setting: the settings on disk for the loaded packages when registration began. Later writes are not seen.
ⓘ
use mod_api::{Host, RegistrationContext};
fn game(_: &dyn Host) {}
fn registration(context: &RegistrationContext) { game(context); }
ⓘ
use mod_api::{prelude::EntitiesHost, RegistrationContext};
fn registration(context: &RegistrationContext) { let _ = EntitiesHost::entity(context, 1); }
ⓘ
use mod_api::{HostTransaction, RegistrationContext};
fn registration(context: &mut RegistrationContext) {
    let _: Result<(), ()> = context.transaction(|_, _| Ok(()));
}

Implementations§

§

impl RegistrationContext

pub fn instance_dir(&self) -> Result<&InstanceDirectory, RegistrationReadError>

The instance directory captured before registration, identically on native and wasm. This is data only, not permission to access a filesystem. The value preserves the host OS’s raw path encoding, including non-UTF-8 names.

pub fn mods(&self) -> &LoadedMods

The loaded-mod view, independent of this phase’s event or registrar.

pub fn registry( &self, name: &str, ) -> Result<Arc<[String]>, RegistrationReadError>

A built-in registry’s names in ID order, for validating the keys a mod declares.

pub fn setting( &self, mod_id: &str, key: &str, ) -> Result<Option<String>, RegistrationReadError>

A loaded mod’s setting as it was when registration began: Ok(None) when the mod has not set it. The key is one setting’s name, not a path.

§

impl RegistrationContext

pub fn refuse(&self, reason: &str)

Refuse this mod’s registration with a diagnostic, without panicking. The first reason wins. Reasons exceeding 4096 UTF-8 bytes are truncated at a character boundary; shorter reasons are preserved verbatim. All this mod’s declarations from this registration are discarded, including later declarations, without adding their validation errors to the report. Other mods’ declarations are unchanged. Native and wasm use the same admission path. Returning from Hooks::register immediately is recommended.

Trait Implementations§

§

impl Wire for RegistrationContext

§

const MIN: usize = <Option<crate::InstanceDirectory> as Wire>::MIN

Minimum encoded size, used to reject impossible collection lengths.
§

fn put(&self, out: &mut Writer)

Encodes this value, recording failures on the writer.
§

fn take(input: &mut Reader<'_>) -> Result<RegistrationContext, WireError>

Decodes one value, leaving any following bytes for the caller.
§

fn put_owned(self, out: &mut Writer)

Consumes owned data when a resource’s ownership must cross the boundary.

Auto Trait Implementations§

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.

§

impl<T> Put for T
where T: Wire,

§

fn put_to(&self, out: &mut Writer)

Writes it.
§

impl<T> Record for T
where T: Wire,

§

fn encode(&self, out: &mut Writer)

Writes the argument into a hook call.
§

fn apply(&mut self, bytes: &[u8]) -> Result<(), WireError>

Applies one complete reply, refusing malformed or trailing bytes atomically.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.