basic get command works with items from 0/config defined in test-config.toml

This commit is contained in:
Sebastian Moser
2024-05-30 14:59:47 +02:00
parent 557ac09bc7
commit 38f967db76
23 changed files with 402 additions and 120 deletions

View File

@@ -8,10 +8,11 @@ use crate::error::{MizeError, MizeResult, IntoMizeResult};
use crate::instance::Instance;
use crate::instance::store::Store;
use crate::id::MizeId;
use cbor::Cbor as CborValue;
use ciborium::Value as CborValue;
// a item always has to do with a Instance, which takes care of how it is updated
#[derive(Debug)]
pub struct Item<S: Store + Sized> {
pub id: MizeId,
pub instance: Instance<S>
@@ -22,16 +23,31 @@ pub struct Item<S: Store + Sized> {
pub type ItemData = CborValue;
impl<S: Store> Item<S> {
pub fn id(self) -> MizeId {
self.id
pub fn id(&self) -> &MizeId {
&self.id
}
pub fn value_raw(self) -> MizeResult<Vec<u8>> {
pub fn value_raw(&self) -> MizeResult<Vec<u8>> {
// this will call from the instance which gets the value from the store
Ok(Vec::new())
self.instance.store.get_value_raw(&self.id())
}
}
impl<S: Store> Display for Item<S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.value_raw() {
Ok(value) => match String::from_utf8(value) {
Ok(string) => write!(f, "{}", string),
Err(_) => write!(f, "{:?}", self.value_raw()),
}
Err(err) => {err.log(); Ok(())},
};
return Ok(());
}
}
/*
#[derive(Debug)]