pub struct ChunkNode<'a> { /* private fields */ }Expand description
A lightweight cursor pointing to a specific node in the dependency graph.
This struct contains the logic to read, decompress, and navigate from this node.
It is a “view” into the ParcodeReader and holds a lifetime reference to it.
Implementations§
Source§impl<'a> ChunkNode<'a>
impl<'a> ChunkNode<'a>
Sourcepub fn read_raw(&self) -> Result<Cow<'a, [u8]>>
pub fn read_raw(&self) -> Result<Cow<'a, [u8]>>
Reads and decompresses the local payload of this chunk.
This returns Cow, so if no compression was used, it returns a direct reference
to the mmap (Zero-Copy). If compressed, it allocates the decompressed buffer.
Sourcepub fn children(&self) -> Result<Vec<Self>>
pub fn children(&self) -> Result<Vec<Self>>
Returns a list of all direct child nodes.
This allows manual traversal of the dependency graph (e.g., iterating over specific shards). Note: This does not deserialize the children, only loads their metadata (offsets).
Sourcepub fn decode<T: DeserializeOwned>(&self) -> Result<T>
pub fn decode<T: DeserializeOwned>(&self) -> Result<T>
Standard single-threaded deserialization. Use this for leaf nodes or simple structs that fit in memory.
Sourcepub fn decode_parallel_collection<T>(&self) -> Result<Vec<T>>where
T: ParcodeItem,
pub fn decode_parallel_collection<T>(&self) -> Result<Vec<T>>where
T: ParcodeItem,
Parallel Shard Reconstruction
Reconstructs a Vec<T> by deserializing shards concurrently.
§Safety
This function uses unsafe to write directly into an uninitialized buffer.
To ensure safety:
- We pre-calculate correct offsets using RLE metadata.
- We cast the buffer pointer to
usizeto safely pass it to Rayon threads. - We verify that the number of items read from a shard matches
the RLE expectation (
expected_count). If not, we abort before writing, preventing partial initialization UB.
Sourcepub fn get<T: ParcodeItem>(&self, index: usize) -> Result<T>
pub fn get<T: ParcodeItem>(&self, index: usize) -> Result<T>
Retrieves item at index using RLE arithmetic.
This calculates which shard holds the item, loads ONLY that shard, and returns the specific item.
Sourcepub fn iter<T: ParcodeItem>(self) -> Result<ChunkIterator<'a, T>>
pub fn iter<T: ParcodeItem>(self) -> Result<ChunkIterator<'a, T>>
Creates a streaming iterator over the collection. Memory usage is constant (size of one shard) regardless of total size.
Sourcepub fn get_child_by_index(&self, index: usize) -> Result<Self>
pub fn get_child_by_index(&self, index: usize) -> Result<Self>
Retrieves a child ChunkNode by its index in the footer.
Sourcepub fn child_count(&self) -> u32
pub fn child_count(&self) -> u32
Returns the number of children.
Sourcepub fn payload_len(&self) -> u64
pub fn payload_len(&self) -> u64
Calculates the size of the payload (excluding metadata/footer).
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ChunkNode<'a>
impl<'a> !RefUnwindSafe for ChunkNode<'a>
impl<'a> Send for ChunkNode<'a>
impl<'a> Sync for ChunkNode<'a>
impl<'a> Unpin for ChunkNode<'a>
impl<'a> !UnwindSafe for ChunkNode<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more