pub struct ResourceStore { /* private fields */ }Expand description
Flat-buffer refcounted resource store. Index 0 is reserved for ResourceId::NONE.
Implementations§
Source§impl ResourceStore
impl ResourceStore
Sourcepub fn words_live(&self) -> usize
pub fn words_live(&self) -> usize
Number of live u32 words currently occupied in the payload slab.
Sourcepub fn child_edges_live(&self) -> usize
pub fn child_edges_live(&self) -> usize
Number of live child ResourceId edges currently occupied in the child slab.
Sourcepub fn try_intern_words<R: FlatResource>(
&mut self,
words: &[u32],
) -> Option<ResourceId>
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.
Sourcepub fn try_intern_with<R: FlatResource>(
&mut self,
write: impl FnOnce(&mut Vec<u32>) -> bool,
) -> Option<ResourceId>
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).
Sourcepub fn try_intern<R: FlatResource>(&mut self, value: &R) -> Option<ResourceId>
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.
Sourcepub fn intern<R: FlatResource>(&mut self, value: &R) -> ResourceId
pub fn intern<R: FlatResource>(&mut self, value: &R) -> ResourceId
Interns value, returning ResourceId::NONE if validation or encode-side limits fail.
Sourcepub fn try_set_ephemeral_with<R: FlatResource>(
&mut self,
old: ResourceId,
write: impl FnOnce(&mut Vec<u32>) -> bool,
) -> Option<ResourceId>
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.
Sourcepub fn try_set_ephemeral<R: FlatResource>(
&mut self,
old: ResourceId,
value: &R,
) -> Option<ResourceId>
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.
Sourcepub fn set_ephemeral<R: FlatResource>(
&mut self,
old: ResourceId,
value: &R,
) -> ResourceId
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).
Sourcepub fn retain(&mut self, id: ResourceId)
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.
Sourcepub fn release(&mut self, id: ResourceId)
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.
Sourcepub fn get<R: FlatResource>(&self, id: ResourceId) -> Option<R::View<'_>>
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.
Sourcepub fn raw_words(&self, id: ResourceId) -> Option<&[u32]>
pub fn raw_words(&self, id: ResourceId) -> Option<&[u32]>
Raw flat u32 words of id (if occupied with matching generation).
Sourcepub fn payload_bytes(&self, id: ResourceId) -> Option<&[u8]>
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.
Sourcepub fn children_of(&self, id: ResourceId) -> &[ResourceId]
pub fn children_of(&self, id: ResourceId) -> &[ResourceId]
Sorted, deduplicated child ResourceId dependencies owned by id.
pub fn kind(&self, id: ResourceId) -> Option<Key64>
pub fn is_live(&self, id: ResourceId) -> bool
Sourcepub fn is_live_of<R: FlatResource>(&self, id: ResourceId) -> bool
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).
Sourcepub fn is_live_with_kind(&self, id: ResourceId, kind: Key64) -> bool
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.