ParcodeNative

Trait ParcodeNative 

Source
pub trait ParcodeNative: Sized {
    // Required method
    fn from_node(node: &ChunkNode<'_>) -> Result<Self>;
}
Expand description

A trait for types that know how to reconstruct themselves from a ChunkNode.

This trait enables the high-level API (Parcode::load) to automatically select the optimal reconstruction strategy based on the type being read.

§Strategy Selection

Different types use different reconstruction strategies:

  • Vec<T>: Parallel reconstruction across shards (see ChunkNode::decode_parallel_collection)
  • HashMap<K, V>: Shard merging with SOA deserialization
  • Primitives: Direct bincode deserialization
  • Custom Structs: Sequential deserialization of local fields + recursive child loading

§Automatic Implementation

This trait is automatically implemented by the #[derive(ParcodeObject)] macro for custom structs. Primitive types and standard collections have manual implementations in this module.

§Example

use parcode::Parcode;

// Automatically selects parallel reconstruction for Vec
let data = vec![1, 2, 3];
Parcode::save("numbers_native.par", &data).unwrap();
let data: Vec<i32> = Parcode::load("numbers_native.par").unwrap();

// Automatically selects sequential deserialization for primitives
let val = 42;
Parcode::save("value_native.par", &val).unwrap();
let value: i32 = Parcode::load("value_native.par").unwrap();

Required Methods§

Source

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Reconstructs the object from the given graph node.

This method is called by Parcode::load after opening the file and locating the root chunk. Implementations should choose the most efficient reconstruction strategy for their type.

§Parameters
  • node: The chunk node to reconstruct from (typically the root node)
§Returns

The fully reconstructed object of type Self.

§Errors

Returns an error if:

  • Decompression fails
  • Deserialization fails (type mismatch, corrupted data)
  • Child nodes are missing or invalid

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.

Implementations on Foreign Types§

Source§

impl ParcodeNative for bool

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for f32

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for f64

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for i8

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for i16

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for i32

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for i64

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for i128

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for isize

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for u8

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for u16

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for u32

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for u64

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for u128

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for usize

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl ParcodeNative for String

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl<K, V> ParcodeNative for HashMap<K, V>

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Source§

impl<T> ParcodeNative for Vec<T>
where T: ParcodeItem,

Uses Parallel Stitching.

Source§

fn from_node(node: &ChunkNode<'_>) -> Result<Self>

Implementors§