pub trait ParcodeItem:
Sized
+ Send
+ Sync
+ 'static {
// Required method
fn read_from_shard(
reader: &mut Cursor<&[u8]>,
children: &mut IntoIter<ChunkNode<'_>>,
) -> Result<Self>;
// Provided methods
fn read_slice_from_shard(
reader: &mut Cursor<&[u8]>,
children: &mut IntoIter<ChunkNode<'_>>,
) -> Result<Vec<Self>> { ... }
fn read_into_slice(
reader: &mut Cursor<&[u8]>,
children: &mut IntoIter<ChunkNode<'_>>,
destination: &mut [MaybeUninit<Self>],
) -> Result<usize> { ... }
}Expand description
A trait for types that can be read from a shard (payload + children).
This trait is used internally during parallel reconstruction to deserialize individual items or slices of items from shard payloads. It provides two methods:
read_from_shard: Reads a single itemread_slice_from_shard: Reads multiple items (optimized)
§Automatic Implementation
This trait is automatically implemented by the #[derive(ParcodeObject)] macro. Primitive
types have optimized implementations that use bulk deserialization.
§Thread Safety
Implementations must be Send + Sync + 'static to support parallel reconstruction across
threads. This is automatically satisfied for most types.
Required Methods§
Sourcefn read_from_shard(
reader: &mut Cursor<&[u8]>,
children: &mut IntoIter<ChunkNode<'_>>,
) -> Result<Self>
fn read_from_shard( reader: &mut Cursor<&[u8]>, children: &mut IntoIter<ChunkNode<'_>>, ) -> Result<Self>
Reads a single item from the shard payload and children.
This method is called during deserialization to reconstruct individual items from a shard’s payload. For types with chunkable fields, this method should deserialize local fields from the reader and reconstruct remote fields from the children iterator.
§Parameters
reader: Cursor over the shard’s decompressed payloadchildren: Iterator over child nodes (for chunkable fields)
§Returns
The deserialized item.
§Errors
Returns an error if deserialization fails or children are missing.
Provided Methods§
Sourcefn read_slice_from_shard(
reader: &mut Cursor<&[u8]>,
children: &mut IntoIter<ChunkNode<'_>>,
) -> Result<Vec<Self>>
fn read_slice_from_shard( reader: &mut Cursor<&[u8]>, children: &mut IntoIter<ChunkNode<'_>>, ) -> Result<Vec<Self>>
DEPRECATED in favor of read_into_slice internally, but kept for API compat.
Default impl now delegates to read_into_slice to reduce code duplication.
Sourcefn read_into_slice(
reader: &mut Cursor<&[u8]>,
children: &mut IntoIter<ChunkNode<'_>>,
destination: &mut [MaybeUninit<Self>],
) -> Result<usize>
fn read_into_slice( reader: &mut Cursor<&[u8]>, children: &mut IntoIter<ChunkNode<'_>>, destination: &mut [MaybeUninit<Self>], ) -> Result<usize>
Reads items directly into a destination slice of uninitialized memory.
§Performance
This method avoids allocating a temporary Vec<T>, writing directly to the final buffer.
§Safety
The implementation must ensure it does not write past the end of destination.
It returns the number of items actually written.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.