worterbuch-common 1.5.0

Client library for Wörterbuch.
Documentation
use crate::{KeyValuePair, ValueEntry};

impl redb::Value for ValueEntry {
    type SelfType<'a> = ValueEntry;

    type AsBytes<'a> = Vec<u8>;

    fn fixed_width() -> Option<usize> {
        None
    }

    fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>
    where
        Self: 'a,
    {
        serde_json::from_slice(data).expect("ValueEntry deserialization failed")
    }

    fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>
    where
        Self: 'b,
    {
        serde_json::to_string(value)
            .expect("ValueEntry serialization failed")
            .into_bytes()
    }

    fn type_name() -> redb::TypeName {
        redb::TypeName::new(std::any::type_name::<ValueEntry>())
    }
}

impl redb::Value for KeyValuePair {
    type SelfType<'a> = KeyValuePair;

    type AsBytes<'a> = Vec<u8>;

    fn fixed_width() -> Option<usize> {
        None
    }

    fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>
    where
        Self: 'a,
    {
        serde_json::from_slice(data).expect("KeyValuePair deserialization failed")
    }

    fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>
    where
        Self: 'b,
    {
        serde_json::to_string(value)
            .expect("KeyValuePair serialization failed")
            .into_bytes()
    }

    fn type_name() -> redb::TypeName {
        redb::TypeName::new(std::any::type_name::<KeyValuePair>())
    }
}