Skip to main content

Pco

Derive Macro Pco 

Source
#[derive(Pco)]
Expand description

Derives the Pco trait for single-field tuple structs containing numeric types.

This macro enables custom wrapper types to work with PcoVec for compressed storage of numeric data using Pcodec compression.

§Requirements

  • Must be a tuple struct with exactly one field
  • The inner type must implement Pco (numeric types: u16-u64, i16-i64, f32, f64)
  • Supports generic type parameters

§Generated Implementation

The derive generates three trait implementations:

  1. Bytes - For serialization (same as #[derive(Bytes)])
  2. Pco - Specifies the numeric type for compression
  3. TransparentPco - Marker trait for transparent wrappers
impl Pco for Wrapper<T> where T: Pco + Bytes {
    type NumberType = <T as Pco>::NumberType;
}

impl TransparentPco<<T as Pco>::NumberType> for Wrapper<T>
where T: Pco + Bytes {}

impl Bytes for Wrapper<T> where T: Pco + Bytes {
    // ... same as Bytes derive
}

The NumberType is automatically propagated from the inner type, ensuring the wrapper has the same compression characteristics.

§Example

use vecdb::{Pco, PcoVec};

#[derive(Pco)]
struct Price(f64);

#[derive(Pco)]
struct NumericWrapper<T>(T); // Generic types supported

// Nested generics work too
#[derive(Pco)]
struct Container<T>(NumericWrapper<T>);