Module resources

Expand description

See resources for the system contract and examples. Typed singleton engine resources without string keys or unsafe downcasts. At most 256 distinct types. Values are host-owned and may have arbitrary size. This single-threaded store does not impose Send/Sync on resources.

Use Resources::get_or_insert_with for lazy setup, Resources::try_init when setup can fail, and Resources::require(crate::resources::Resources::require) for a required dependency. Initializers run only for absent types with available capacity. Type names in errors are Rust diagnostic names, not stable serialization identifiers. Use Resources::try_update to validate a replacement before changing an existing resource; successful updates return ownership of the previous value.

For simultaneous access to distinct types, use Resources::with2_mut or Resources::with3_mut. Mixed access is available through Resources::with2_mut_ref, Resources::with3_mut_mut_ref and Resources::with3_mut_ref_ref; put mutable arguments first. All arguments must have distinct TypeIds, including the shared arguments. For entirely shared access, ordinary repeated Resources::require calls suffice. Disjoint access uses scoped ordinary references, never removes entries, and allocates no heap storage of its own. Resource types need not be Clone, Send or Sync. Callback allocations and side effects remain caller-owned.

Structs§

Resources

Enums§

ResourceAccessError
A disjoint resource request repeated a type or requested an absent type.
ResourceError
A required resource is missing, or a new resource would exceed the type limit.
ResourceInitError
A store error or the original error returned by a resource initializer.
ResourceUpdateError
A missing resource or the original error returned by a checked update.