Geoffrey-rs/geoffrey_models/src/lib.rs

35 lines
806 B
Rust

#![allow(dead_code)]
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::fmt::Debug;
pub mod models;
const DB_VERSION: u64 = 1;
pub trait GeoffreyDatabaseModel: Serialize + DeserializeOwned + Debug {
fn id(&self) -> Option<u64>;
fn set_id(&mut self, id: u64);
fn tree() -> String;
fn check_unique(&self, _: &Self) -> bool {
true
}
fn to_json_string(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(self)
}
fn try_from_str(s: &str) -> Result<Self, serde_json::Error> {
serde_json::from_str(s)
}
fn to_bytes(&self) -> Result<Vec<u8>, serde_json::Error> {
serde_json::to_vec(self)
}
fn try_from_bytes(b: &[u8]) -> Result<Self, serde_json::Error> {
serde_json::from_slice(b)
}
}