1
This commit is contained in:
parent
8ff8a9b2d3
commit
d1e57513bb
@ -1,3 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -16,8 +17,8 @@ pub struct MetaMgr {
|
||||
|
||||
impl MetaMgr {
|
||||
|
||||
pub fn register_meta_class(&mut self) {
|
||||
let a = MetaClass{
|
||||
pub fn register_meta_class(&mut self, file_name: String, idx: i32, prim_key: String, sec_key: String) {
|
||||
let cls = MetaClass{
|
||||
file_name: String::from("hello"),
|
||||
idx: 1,
|
||||
prim_key: String::from("key"),
|
||||
@ -25,6 +26,23 @@ impl MetaMgr {
|
||||
id_hash: HashMap::new(),
|
||||
name_hash: HashMap::new()
|
||||
};
|
||||
self.meta_classes.push(Box::new(cls));
|
||||
}
|
||||
|
||||
pub fn get_byid<T: 'static>(&mut self, idx: i32, id: i64) -> Option<&Rc<T>> {
|
||||
if (idx as usize) < self.meta_classes.len() {
|
||||
match self.meta_classes[idx as usize].id_hash.get(&id) {
|
||||
Some(v) => {
|
||||
if let Some(item) = v.downcast_ref::<Rc<T>>() {
|
||||
return Some(item)
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user