diff --git a/Cargo.lock b/Cargo.lock index 6fb572f..a8514e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,11 +4,11 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ - "gimli 0.28.1", + "gimli 0.29.0", ] [[package]] @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27a4bd113ab6da4cd0f521068a6e2ee1065eab54107266a11835d02c8ec86a37" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "ascii" @@ -125,7 +125,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", ] [[package]] @@ -226,14 +226,14 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", ] [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" dependencies = [ "addr2line", "cc", @@ -323,9 +323,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.97" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" [[package]] name = "cfg-if" @@ -448,9 +448,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] @@ -476,9 +476,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" @@ -692,9 +692,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -714,9 +714,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "half" @@ -934,6 +934,11 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "interner" +version = "0.2.1" +source = "git+https://github.com/c2vi/interner#746e7586bb65e2e50ac02140c6414574efb2eb4e" + [[package]] name = "is-terminal" version = "0.4.12" @@ -980,9 +985,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "linux-raw-sys" @@ -1026,9 +1031,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -1058,6 +1063,7 @@ dependencies = [ "daemonize", "env_logger 0.10.2", "home", + "interner", "log", "nix", "serde", @@ -1134,9 +1140,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" dependencies = [ "memchr", ] @@ -1170,7 +1176,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", ] [[package]] @@ -1199,9 +1205,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" dependencies = [ "unicode-ident", ] @@ -1437,7 +1443,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", ] [[package]] @@ -1561,9 +1567,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.64" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1599,22 +1605,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", ] [[package]] @@ -1676,9 +1682,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "bytes", @@ -2020,7 +2026,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -2106,7 +2112,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2149,7 +2155,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.64", + "syn 2.0.66", ] [[package]] @@ -2409,6 +2415,6 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index 85f2f5a..2e5bd12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ log = "0.4.20" tokio = { version = "1.21.0", features = ["sync"] } ciborium = { version = "0.2.2", default-features = false } serde = "1.0.203" +interner = { git = "https://github.com/c2vi/interner" } # wasm dependencies wasm-bindgen = { version = "0.2.84", optional = true } diff --git a/flake.nix b/flake.nix index 3847e26..9c2433f 100644 --- a/flake.nix +++ b/flake.nix @@ -90,14 +90,14 @@ in { (fenix.packages.${system}.combine [ wasmToolchain osToolchain ]) ]; shellHook = '' - export MIZE_CONFIG_FILE=${self}/default-config.toml + export MIZE_CONFIG_FILE=${self}/test-config.toml ''; }; }) // { ############################## SOME GLOBAL OUTPUTS ############################## - inherit inputs; + inherit inputs self; }; } diff --git a/src/core/id.rs b/src/core/id.rs index c94d715..f2a78ed 100644 --- a/src/core/id.rs +++ b/src/core/id.rs @@ -1,20 +1,29 @@ use core::fmt; -use std::{fmt::write, hash::Hash}; +use std::{collections::binary_heap::Iter, fmt::write, hash::Hash}; +use interner::{shared::SharedPool, Pooled, shared::SharedVecString}; +use std::collections::hash_map::RandomState; +use crate::instance::{store::Store, Instance}; #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct MizeId { - path: Vec + pub path: SharedVecString, } impl MizeId { pub fn store_part(&self) -> &str { - self.path.first() + self.path.iter().nth(0) .expect("an empty MizeId found, that should absolutely not be possible!!!!").as_str() } - pub fn as_vec(self) -> Vec { - self.path + pub fn path(&self) -> SharedVecString { + self.path.clone() } + //pub fn as_slice(&self) -> u8 { + //self.path + //} + //pub fn as_iter(&self) -> u8 { + //self.path.iter() + //} } impl fmt::Display for MizeId { @@ -23,12 +32,63 @@ impl fmt::Display for MizeId { } } -impl> From for MizeId { - fn from(value: T) -> Self { - let string = value.into(); - let path: Vec = string.split("/").map(|v| v.to_owned()).collect(); - return MizeId { path } +pub trait IntoMizeId { + fn to_mize_id(self, instance: &Instance) -> MizeId; +} + +impl IntoMizeId for &str { + fn to_mize_id(self, instance: &Instance) -> MizeId { + instance.id_from_string(self.to_owned()) } } +impl IntoMizeId for String { + fn to_mize_id(self, instance: &Instance) -> MizeId { + instance.id_from_string(self) + } +} +impl IntoMizeId for &String { + fn to_mize_id(self, instance: &Instance) -> MizeId { + instance.id_from_string(self.to_owned()) + } +} +impl IntoMizeId for Vec { + fn to_mize_id(self, instance: &Instance) -> MizeId { + instance.id_from_vec_string(self) + } +} +impl IntoMizeId for &[&str] { + fn to_mize_id(self, instance: &Instance) -> MizeId { + let mut vec: Vec = Vec::new(); + for i in self { + vec.push((*i).to_owned()) + } + instance.id_from_vec_string(vec) + } +} +impl IntoMizeId for Vec<&str> { + fn to_mize_id(self, instance: &Instance) -> MizeId { + let mut vec: Vec = Vec::new(); + for i in self { + vec.push((*i).to_owned()) + } + instance.id_from_vec_string(vec) + } +} +impl IntoMizeId for MizeId { + fn to_mize_id(self, instance: &Instance) -> MizeId { + self + } +} + +// would only work with a global id_pool +// for now use Instance::new_id() +//impl> From for MizeId { + //fn from(value: T) -> Self { + //let string = value.into(); + //let path: Vec = string.split("/").map(|v| v.to_owned()).collect(); + //return MizeId { MIZE_ID_POOL.get(path) } + //} +//} + diff --git a/src/core/instance/mod.rs b/src/core/instance/mod.rs index 152e783..2c3ac57 100644 --- a/src/core/instance/mod.rs +++ b/src/core/instance/mod.rs @@ -7,11 +7,12 @@ use uuid::Uuid; use std::fs::File; use colored::Colorize; use std::path::Path; +use interner::shared::VecStringPool; use crate::error::{MizeError, MizeResult, IntoMizeResult, MizeResultTrait}; use crate::instance::store::Store; use crate::instance::connection::Connection; -use crate::id::MizeId; +use crate::id::{IntoMizeId, MizeId}; use crate::instance::subscription::Subscription; use crate::item::{Item, ItemData}; use crate::memstore::MemStore; @@ -31,6 +32,7 @@ pub struct Instance { pub store: S, peers: Arc>>>, subs: Arc>>, + pub id_pool: VecStringPool, } @@ -46,36 +48,73 @@ impl Instance { pub fn new() -> MizeResult> { trace!("[ {} ] Instance::new()", "CALL".yellow()); - let memstore = MemStore::new(); - let instance = Instance {store: memstore, peers: Arc::new(Mutex::new(Vec::new())), subs: Arc::new(Mutex::new(HashMap::new())) }; + let store = MemStore::new(); + let id_pool = VecStringPool::default(); + let peers = Arc::new(Mutex::new(Vec::new())); + let subs = Arc::new(Mutex::new(HashMap::new())); + let mut instance = Instance {store, peers, subs, id_pool }; + instance.init(); + + return Ok(instance); + } + + fn init(&mut self) -> MizeResult<()> { // platform specific init code if cfg!(feature = "os-target") { // on os platforms - crate::platform::os::os_instance_init(instance.clone())? + crate::platform::os::os_instance_init(self)? } // end of platform specific init code + Ok(()) + } - return Ok(instance); + pub fn with_config(config: ItemData) -> MizeResult> { + let mut instance = Instance::new()?; + instance.set("0", config.clone()); + instance.init()?; + + // set it again, so that the passed config data has presidence over anything the init would set + instance.set("0", config); + + Ok(instance) } } impl Instance { - pub fn new_item(self) -> MizeResult> { - let id = self.store.new_id()?; + pub fn new_item(&self) -> MizeResult> { + let id = self.id_from_string(self.store.new_id()?); return Ok(Item {id, instance: self}); } - pub fn get>(self, id: I) -> MizeResult> { - return Ok(Item {id: id.into(), instance: self}); + pub fn get>(&self, id: I) -> MizeResult> { + let id = id.to_mize_id(self); + return Ok(Item {id: id.to_mize_id(self), instance: self}); } - pub fn set, V: Into>(self, id: I, value: V) -> MizeResult<()> { - self.store.set(&id.into(), value) + pub fn set, V: Into>(&mut self, id: I, value: V) -> MizeResult<()> { + let id = id.to_mize_id(self); + self.store.set(id, value) } + pub fn new_id>(&self, value: T) -> MizeId { + value.to_mize_id(self) + } + + pub fn id_from_string(&self, string: String) -> MizeId { + let vec_string: Vec = string.split("/").map(|v| v.to_owned()).collect(); + return MizeId { path: self.id_pool.get(vec_string) }; + } + pub fn id_from_vec_string(&self, vec_string: Vec) -> MizeId { + return MizeId { path: self.id_pool.get(vec_string) }; + } +//impl> From for MizeId { + //fn from(value: T) -> Self { + //} +//} + } impl fmt::Debug for Instance { diff --git a/src/core/instance/store.rs b/src/core/instance/store.rs index 3b304c6..ea84b21 100644 --- a/src/core/instance/store.rs +++ b/src/core/instance/store.rs @@ -9,21 +9,17 @@ pub trait Store { // is implemented, so that there can be a multithreaded implementation //fn get(self, id: MizeId) -> MizeResult> where Self: Sized; - fn set>(self, id: &MizeId, data: T) -> MizeResult<()>; + fn set>(&mut self, id: MizeId, data: T) -> MizeResult<()>; // in the future should implement transactions, .... // funcs to do with links, backlinks - fn get_links(self, item: Item) -> MizeResult> where Self: Sized; + fn get_links(&self, item: Item) -> MizeResult> where Self: Sized; - fn get_backlinks(self, item: Item) -> MizeResult> where Self: Sized; + fn get_backlinks(&self, item: Item) -> MizeResult> where Self: Sized; - fn new_id(&self) -> MizeResult; + fn new_id(&self) -> MizeResult; - fn get_value_raw(&self, id: &MizeId) -> MizeResult>; + fn get_value_raw(&self, id: MizeId) -> MizeResult>; } -/// references an item that is stored in a store -pub trait StoreRef { - // do we need this or is this basically an item -} diff --git a/src/core/item.rs b/src/core/item.rs index 1598bc4..5da5723 100644 --- a/src/core/item.rs +++ b/src/core/item.rs @@ -13,30 +13,30 @@ 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 { +pub struct Item<'a, S: Store + Sized> { pub id: MizeId, - pub instance: Instance + pub instance: &'a Instance } // without an Instance it is not an item, but only the "data of an item" // and this type for now is just an alias to CborValue pub type ItemData = CborValue; -impl Item { - pub fn id(&self) -> &MizeId { - &self.id +impl Item<'_, S> { + pub fn id(&self) -> MizeId { + self.id.clone() } pub fn value_raw(&self) -> MizeResult> { // this will call from the instance which gets the value from the store - self.instance.store.get_value_raw(&self.id()) + self.instance.store.get_value_raw(self.id()) } } -impl Display for Item { +impl 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(value) => match String::from_utf8(value.to_owned()) { Ok(string) => write!(f, "{}", string), Err(_) => write!(f, "{:?}", self.value_raw()), } diff --git a/src/core/memstore.rs b/src/core/memstore.rs index d8cdfe4..4aa0dd8 100644 --- a/src/core/memstore.rs +++ b/src/core/memstore.rs @@ -1,3 +1,4 @@ +use std::collections::binary_heap::Iter; use std::collections::HashMap; use std::iter::Map; use std::sync::{Arc, Mutex}; @@ -14,6 +15,8 @@ pub struct MemStore { inner: Arc>, } +pub type MemStoreId = u64; + #[derive(Debug)] struct MemStoreInner { map: HashMap, @@ -21,39 +24,43 @@ struct MemStoreInner { } impl Store for MemStore { - fn set>(mut self, id: &MizeId, data: T) -> MizeResult<()> { + fn set>(&mut self, id: MizeId, data: T) -> MizeResult<()> { let mut inner = self.inner.lock()?; inner.map.insert(id_to_u64(id)?, data.into()); return Ok(()) } - fn get_links(self, item: Item) -> MizeResult> { + fn get_links(&self, item: Item) -> MizeResult> { let inner = self.inner.lock()?; Ok(Vec::new()) } - fn get_backlinks(self, item: Item) -> MizeResult> { + fn get_backlinks(&self, item: Item) -> MizeResult> { let inner = self.inner.lock()?; Ok(Vec::new()) } - fn new_id(&self) -> MizeResult { - let inner = self.inner.lock()?; + fn new_id(&self) -> MizeResult { + let mut inner = self.inner.lock()?; let id_string = format!("{}", inner.next_id); - return Ok(id_string.into()); + inner.next_id += 1; + return Ok(id_string); } - fn get_value_raw(&self, id: &MizeId) -> MizeResult> { + fn get_value_raw(&self, id: MizeId) -> MizeResult> { let inner = self.inner.lock()?; - let cbor_val = inner.map.get(&id_to_u64(id)?) + let cbor_val = inner.map.get(&id_to_u64(id.clone())?) .ok_or(MizeError::new() - .msg(format!("Item with store_part: {}, id: {} does not exist in MemStore", id_to_u64(id)?, id)))?; + .msg(format!("Item with store_part: {}, id: {} does not exist in MemStore", id_to_u64(id.clone())?, id)))?; - let mut id_without_first = id.clone().as_vec(); - id_without_first.remove(0); - get_raw_from_cbor(cbor_val.to_owned(), id_without_first) + let path = id.path(); + let mut id_iter = path.iter(); + id_iter.next(); + let id_without_first = id_iter.collect(); + + Ok(get_raw_from_cbor(cbor_val, id_without_first)?.to_owned()) } } @@ -64,34 +71,39 @@ impl MemStore { } } -fn id_to_u64(id: &MizeId) -> MizeResult { +fn id_to_u64(id: MizeId) -> MizeResult { id.store_part() .parse() .mize_result_msg(format!("Could not parse the store_part of mizeid {} into a u64 for the MemStore", id)) } -fn get_raw_from_cbor(value: CborValue, mut path: Vec) -> MizeResult> { +fn get_raw_from_cbor<'a>(value: &'a CborValue, path: Vec<&String>) -> MizeResult<&'a [u8]> { match value { - CborValue::Bytes(vec) => Ok(vec), - CborValue::Text(string) => Ok(string.into_bytes()), + CborValue::Bytes(vec) => Ok(&vec[..]), + CborValue::Text(string) => Ok(string.as_bytes()), CborValue::Map(map) => { - let mut inner_val: CborValue = CborValue::Null; - trace!("map: {:?}", map); + let mut inner_val: &CborValue = &CborValue::Null; + trace!("map: {:?}", map); for (key, val) in map.into_iter() { - let first_path_string = path.first() - .ok_or(MizeError::new().msg("get_raw_from_cbor: path is empty"))?; + let first_path_string = *path.iter().nth(0) + .ok_or(MizeError::new() + .msg("get_raw_from_cbor: path is empty"))?; if let CborValue::Text(key_text) = key { - if key_text == *first_path_string { + if key_text == first_path_string { inner_val = val } } } - if inner_val == CborValue::Null { - return Err(MizeError::new().msg(format!("get_raw_from_cbor: Path {} not Found", path.join("/")))) + if inner_val == &CborValue::Null { + return Err(MizeError::new() + // jesus christ, this is a pfusch... + .msg(format!("get_raw_from_cbor: Path {} not Found", path.clone().into_iter().map(|v| v.to_owned()).collect::>().join("/")))) } - path.remove(0); - get_raw_from_cbor(inner_val, path) + let mut path_iter = path.into_iter(); + path_iter.next(); + let inner_path = path_iter.collect(); + get_raw_from_cbor(inner_val, inner_path) }, _ => Err(MizeError::new().msg("get_raw_from_cbor: value is not Bytes, Text or Map")), } diff --git a/src/platform/os/cli/run.rs b/src/platform/os/cli/run.rs index 01be002..13418ae 100644 --- a/src/platform/os/cli/run.rs +++ b/src/platform/os/cli/run.rs @@ -12,7 +12,15 @@ use mize::instance::Instance; pub fn run(sub_matches: &ArgMatches) -> MizeResult<()> { - let instance = Instance::new(); + // TODO NEXT!!! + // - add --system arg + // - add --user arg + // - --config arg + // - to set a location, where there will be a /store and a /sock + // - listen for connections on that sock + // - msg handeling + let instance = Instance::with_config(todo!()); + /* let instance_path = match sub_matches.get_one::("store") { Some(a) => PathBuf::from(a), diff --git a/src/platform/os/main.rs b/src/platform/os/main.rs index 44c9d94..0bc198f 100644 --- a/src/platform/os/main.rs +++ b/src/platform/os/main.rs @@ -260,10 +260,10 @@ fn level_from_env(var_name: &str, log_level: LevelFilter) -> (Option clap::ArgMatches { - let store_arg = Arg::new("store") - .short('s') - .long("store") - .help("The folder used as the Itemstore"); + let folder_arg = Arg::new("folder") + .short('f') + .long("folder") + .help("The folder the Instance stores all it's data and the socket for connections"); let main = Command::new(APPNAME) .version(crate_version!()) @@ -284,6 +284,7 @@ fn cli_matches() -> clap::ArgMatches { .action(ArgAction::SetTrue) .help("set the log-level to OFF") ) + .arg(&folder_arg) .subcommand( Command::new("run") .aliases(["r"]) @@ -295,30 +296,29 @@ fn cli_matches() -> clap::ArgMatches { .subcommand( Command::new("mount") .aliases(["m"]) - .arg(&store_arg) ) .subcommand( Command::new("get") .aliases(["g"]) - .arg(&store_arg) + .arg(&folder_arg) .arg(Arg::new("id").help("The id or path to get")) ) .subcommand( Command::new("set") .aliases(["s"]) - .arg(&store_arg) + .arg(&folder_arg) .arg(Arg::new("id").help("The id or path to set")) ) .subcommand( Command::new("show") .aliases(["so"]) - .arg(&store_arg) + .arg(&folder_arg) .arg(Arg::new("id").help("The id or path to sub to and show")) ) .subcommand( Command::new("call") .aliases(["c"]) - .arg(&store_arg) + .arg(&folder_arg) ) .arg_required_else_help(true); diff --git a/src/platform/os/mod.rs b/src/platform/os/mod.rs index 22c7c91..bb0a760 100644 --- a/src/platform/os/mod.rs +++ b/src/platform/os/mod.rs @@ -8,10 +8,10 @@ use crate::instance::Instance; use crate::error::{IntoMizeResult, MizeError, MizeResult}; -pub fn os_instance_init(instance: Instance) -> MizeResult<()> { +pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> { // this is the code, that runs to initialize an Instance on a system with an os present. - // load MIZE_CONFIG_FILE as the instance, which is item 0 + ////// load MIZE_CONFIG_FILE as the instance, which is item 0 let config_file_path = std::env::var("MIZE_CONFIG_FILE") .mize_result_msg("Could not get the MIZE_CONFIG_FILE Environment Variable")?; @@ -24,6 +24,9 @@ pub fn os_instance_init(instance: Instance) -> MizeResult<()> { .mize_result_msg(format!("Could not deserialize the content of MIZE_CONFIG_FILE at {}", &config_file_path))?; instance.set("0", config)?; + + ////// load config from MIZE_CONFIG env var + //TODO return Ok(()); }