added namespace
This commit is contained in:
@@ -1,29 +1,50 @@
|
||||
use core::fmt;
|
||||
use std::{collections::binary_heap::Iter, fmt::write, hash::Hash};
|
||||
use interner::{shared::SharedPool, Pooled, shared::SharedVecString};
|
||||
use interner::{shared::{SharedPool, SharedString, SharedVecString}, Pooled};
|
||||
use std::collections::hash_map::RandomState;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::instance::{store::Store, Instance};
|
||||
|
||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||
pub struct MizeId {
|
||||
pub path: SharedVecString,
|
||||
pub namespace: Namespace,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||
pub struct Namespace ( pub SharedString );
|
||||
|
||||
impl Namespace {
|
||||
fn as_string(self) -> SharedString {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IntoMizeId {
|
||||
fn to_mize_id(self, instance: &Instance) -> MizeId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
impl MizeId {
|
||||
pub fn store_part(&self) -> &str {
|
||||
self.path.iter().nth(0)
|
||||
.expect("an empty MizeId found, that should absolutely not be possible!!!!").as_str()
|
||||
}
|
||||
|
||||
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()
|
||||
//}
|
||||
|
||||
pub fn namespace(&self) -> Namespace {
|
||||
self.namespace.clone()
|
||||
}
|
||||
|
||||
pub fn namespace_str(&self) -> &str {
|
||||
&self.namespace.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MizeId {
|
||||
@@ -32,10 +53,6 @@ impl fmt::Display for MizeId {
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
|
||||
@@ -7,13 +7,13 @@ use uuid::Uuid;
|
||||
use std::fs::File;
|
||||
use colored::Colorize;
|
||||
use std::path::Path;
|
||||
use interner::shared::VecStringPool;
|
||||
use interner::shared::{VecStringPool, StringPool};
|
||||
|
||||
use crate::error::{MizeError, MizeResult, IntoMizeResult, MizeResultTrait};
|
||||
use crate::instance;
|
||||
use crate::instance::store::Store;
|
||||
use crate::instance::connection::Connection;
|
||||
use crate::id::{IntoMizeId, MizeId};
|
||||
use crate::id::{IntoMizeId, MizeId, Namespace};
|
||||
use crate::instance::subscription::Subscription;
|
||||
use crate::item::{Item, ItemData};
|
||||
use crate::memstore::MemStore;
|
||||
@@ -33,26 +33,23 @@ pub struct Instance {
|
||||
peers: Arc<Mutex<Vec<Box<dyn Connection>>>>,
|
||||
subs: Arc<Mutex<HashMap<MizeId, Subscription>>>,
|
||||
pub id_pool: VecStringPool,
|
||||
pub namespace_pool: StringPool,
|
||||
pub namespace: Namespace,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
pub enum RealmId {
|
||||
Uuid(Uuid),
|
||||
Local(Vec<String>),
|
||||
Tld(Vec<String>),
|
||||
}
|
||||
*/
|
||||
|
||||
impl Instance {
|
||||
pub fn empty() -> Instance {
|
||||
let store = MemStore::new();
|
||||
let id_pool = VecStringPool::default();
|
||||
let namespace_pool = StringPool::default();
|
||||
let peers = Arc::new(Mutex::new(Vec::new()));
|
||||
let subs = Arc::new(Mutex::new(HashMap::new()));
|
||||
let mut instance = Instance { store: Box::new(store), peers, subs, id_pool };
|
||||
let namespace = Namespace ( namespace_pool.get("mize.default.namespace") );
|
||||
let mut instance = Instance { store: Box::new(store), peers, subs, id_pool, namespace_pool, namespace };
|
||||
return instance;
|
||||
}
|
||||
|
||||
pub fn new() -> MizeResult<Instance> {
|
||||
trace!("[ {} ] Instance::new()", "CALL".yellow());
|
||||
|
||||
@@ -135,15 +132,16 @@ impl Instance {
|
||||
|
||||
pub fn id_from_string(&self, string: String) -> MizeId {
|
||||
let vec_string: Vec<String> = string.split("/").map(|v| v.to_owned()).collect();
|
||||
return MizeId { path: self.id_pool.get(vec_string) };
|
||||
MizeId { path: self.id_pool.get(vec_string), namespace: self.namespace.clone() }
|
||||
}
|
||||
|
||||
pub fn id_from_vec_string(&self, vec_string: Vec<String>) -> MizeId {
|
||||
return MizeId { path: self.id_pool.get(vec_string) };
|
||||
MizeId { path: self.id_pool.get(vec_string), namespace: self.namespace.clone() }
|
||||
}
|
||||
|
||||
pub fn namespace_from_string(&self, ns_str: String) -> Namespace {
|
||||
Namespace ( self.namespace_pool.get(ns_str) )
|
||||
}
|
||||
//impl<T: Into<String>> From<T> for MizeId {
|
||||
//fn from(value: T) -> Self {
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Instance {
|
||||
|
||||
Reference in New Issue
Block a user