structsy 0.5.2

Simple single file structs database
Documentation
//! Internal APIs used by the generated code to interact with structsy, not for public use
//!
//!
//!
pub use crate::actions::EqualAction;
pub use crate::actions::OrderAction;
pub use crate::actions::QueryAction;
pub use crate::actions::RangeAction;
pub use crate::desc::{
    Description, EnumDescription, EnumDescriptionBuilder, FieldDescription, SimpleValueTypeBuilder, StructDescription,
    StructDescriptionBuilder, ValueTypeBuilder, VariantDescription,
};
pub use crate::filter::Filter;
pub use crate::filter_builder::FilterBuilder;
pub use crate::format::PersistentEmbedded;
pub use crate::index::{declare_index, IndexableValue};
pub use crate::projection::Projection;
pub use crate::queries::EmbeddedQuery;
pub use crate::queries::Query;
use crate::{Ref, SRes, Sytx};
use std::fmt::Debug;
use std::io::{Read, Write};

pub(crate) trait FieldInfo: std::fmt::Debug {
    fn name(&self) -> &'static str;
}

pub struct Field<T, V> {
    pub(crate) name: &'static str,
    pub(crate) access: fn(&T) -> &V,
}
impl<T, V> Clone for Field<T, V> {
    fn clone(&self) -> Self {
        Field {
            name: self.name,
            access: self.access,
        }
    }
}
impl<T, V> Debug for Field<T, V> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Filed:{}", self.name)
    }
}

impl<T, V> Field<T, V> {
    #[inline]
    pub fn new(name: &'static str, access: fn(&T) -> &V) -> Self {
        Field { name, access }
    }
}

impl<T, V> FieldInfo for Field<T, V> {
    fn name(&self) -> &'static str {
        self.name
    }
}

/// Trait for description of embedded structs, automatically generated by structsy_derive.
pub trait EmbeddedDescription: PersistentEmbedded + Sized {
    fn filter() -> Filter<Self> {
        Filter::default()
    }
    fn get_description() -> Description;
}

/// Trait implemented by persistent struct, implementation automatically generated by
/// structsy_derive.
pub trait Persistent: Sized {
    fn filter() -> Filter<Self> {
        Filter::default()
    }
    fn get_name() -> &'static str;
    fn get_description() -> Description;
    fn write(&self, write: &mut dyn Write) -> SRes<()>;
    fn read(read: &mut dyn Read) -> SRes<Self>
    where
        Self: std::marker::Sized;
    fn declare(db: &mut dyn Sytx) -> SRes<()>;
    fn put_indexes(&self, tx: &mut dyn Sytx, id: &Ref<Self>) -> SRes<()>
    where
        Self: std::marker::Sized;
    fn remove_indexes(&self, tx: &mut dyn Sytx, id: &Ref<Self>) -> SRes<()>
    where
        Self: std::marker::Sized;
}