Derive Macro infinitree::Index

source ·
#[derive(Index)]
{
    // Attributes available to this derive:
    #[infinitree]
}
Expand description

Example use of the derive macro:

use infinitree::fields::{Serialized, VersionedMap};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct PlantHealth {
    id: usize,
    air_humidity: usize,
    soil_humidity: usize,
    temperature: f32
}

#[derive(infinitree::Index, Default, Clone)]
pub struct Measurements {
    // rename the field when serializing
    #[infinitree(name = "last_time")]
    _old_last_time: Serialized<String>,

    #[infinitree(name = "last_time2")]
    last_time: Serialized<usize>,

    // only store the keys in the index, not the values
    #[infinitree(strategy = "infinitree::fields::SparseField")]
    measurements: VersionedMap<usize, PlantHealth>,

    // skip the next field when loading & serializing
    #[infinitree(skip)]
    current_time: usize,
}