Skip to main content

ResourceStore

Struct ResourceStore 

Source
pub struct ResourceStore { /* private fields */ }
Expand description

Flat-buffer refcounted resource store. Index 0 is reserved for ResourceId::NONE.

Implementations§

Source§

impl ResourceStore

Source

pub fn word_slab(&self) -> &[u32]

Whole contiguous payload word slab (publishable zero-copy).

Source

pub fn words_live(&self) -> usize

Number of live u32 words currently occupied in the payload slab.

Source

pub fn child_edges_live(&self) -> usize

Number of live child ResourceId edges currently occupied in the child slab.

Source

pub fn try_intern_words<R: FlatResource>( &mut self, words: &[u32], ) -> Option<ResourceId>

Interns words directly (0 allocations on dedup hit), returning None if R::validate fails, words.len() > MAX_SPAN_LEN, or any embedded child resource is not live.

Source

pub fn try_intern_with<R: FlatResource>( &mut self, write: impl FnOnce(&mut Vec<u32>) -> bool, ) -> Option<ResourceId>

Interns via a closure writing flat words directly into the reusable scratch buffer (0 heap allocations on dedup hit once scratch is warm).

Source

pub fn try_intern<R: FlatResource>(&mut self, value: &R) -> Option<ResourceId>

Interns value, returning None if encoding exceeds limits, fails validation, or references a dead child resource.

Source

pub fn intern<R: FlatResource>(&mut self, value: &R) -> ResourceId

Interns value, returning ResourceId::NONE if validation or encode-side limits fail.

Source

pub fn try_set_ephemeral_with<R: FlatResource>( &mut self, old: ResourceId, write: impl FnOnce(&mut Vec<u32>) -> bool, ) -> Option<ResourceId>

Rewrites ephemeral old in place via a zero-alloc scratch closure when uniquely owned and acyclic; otherwise allocates a fresh ephemeral resource.

Source

pub fn try_set_ephemeral<R: FlatResource>( &mut self, old: ResourceId, value: &R, ) -> Option<ResourceId>

Rewrites ephemeral old in place when uniquely owned; otherwise allocates a fresh ephemeral resource. Returns None if encoding/validation fails.

Source

pub fn set_ephemeral<R: FlatResource>( &mut self, old: ResourceId, value: &R, ) -> ResourceId

Rewrites ephemeral old in place (falling back to ResourceId::NONE on invalid input).

Source

pub fn retain(&mut self, id: ResourceId)

Adds a reference to id. When refs transitions 0 -> 1 on a wire-defined resource with children, iteratively retains all transitive child resources.

Source

pub fn release(&mut self, id: ResourceId)

Drops a reference iteratively; when refs reaches 0, cascades releases to transitive children and schedules slot/span recycling at the next frame boundary.

Source

pub fn get<R: FlatResource>(&self, id: ResourceId) -> Option<R::View<'_>>

Zero-copy typed view over id’s flat u32 words.

Local entries were sealed at intern time (O(1) slice load); wire-origin entries are validated once via R::validate + child-span check and cached atomically in Entry so subsequent reads never re-scan payloads.

Source

pub fn raw_words(&self, id: ResourceId) -> Option<&[u32]>

Raw flat u32 words of id (if occupied with matching generation).

Source

pub fn payload_bytes(&self, id: ResourceId) -> Option<&[u8]>

Little-endian byte view of id’s flat words: the exact payload an NV02 DefineResources entry carries and foreign hosts borrow (zero-copy; None for ResourceId::NONE, released, recycled, or stale-generation ids). Valid until the store is next mutated.

Source

pub fn children_of(&self, id: ResourceId) -> &[ResourceId]

Sorted, deduplicated child ResourceId dependencies owned by id.

Source

pub fn kind(&self, id: ResourceId) -> Option<Key64>

Source

pub fn is_live(&self, id: ResourceId) -> bool

Source

pub fn is_live_of<R: FlatResource>(&self, id: ResourceId) -> bool

Returns true iff id is currently live (refs > 0, generation matches) and compatible with resource type R (matching R::KIND and any sealed TypeId).

Source

pub fn is_live_with_kind(&self, id: ResourceId, kind: Key64) -> bool

Returns true iff id is currently live (refs > 0, generation matches) with kind.

Source

pub fn live(&self) -> usize

Number of live resources.

Trait Implementations§

Source§

impl Default for ResourceStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.

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.