This commit is contained in:
aozhiwei 2023-10-07 08:40:55 +08:00
parent 9f8a1d6889
commit a90e99ab62
3 changed files with 42 additions and 14 deletions

View File

@ -1,16 +1,39 @@
pub struct ListHead { use std::rc::{Rc, Weak};
prev: Option<Box<ListHead>>, use std::cell::RefCell;
next: Option<Box<ListHead>>,
pub struct ListHead<T> {
prev: Weak::<RefCell::<ListHead<T>>>,
next: Weak::<RefCell::<ListHead<T>>>,
data: Weak::<RefCell::<T>>,
} }
impl ListHead { impl<T> ListHead<T> {
pub fn new() -> Self { pub fn new() -> Rc::<RefCell::<ListHead<T>>> {
let p = ListHead{ let this = Rc::new(RefCell::new(ListHead{
prev: None, prev: Weak::<RefCell::<ListHead<T>>>::new(),
next: None, next: Weak::<RefCell::<ListHead<T>>>::new(),
}; data: Weak::<RefCell::<T>>::new(),
return p; }));
this.borrow_mut().prev = Rc::downgrade(&this);
this.borrow_mut().next = Rc::downgrade(&this);
return this;
}
pub fn data(&self) -> &Weak::<RefCell::<T>> {
return &self.data;
}
pub fn del(&mut self) {
self.next.upgrade().unwrap().borrow_mut().prev = self.prev.clone();
self.prev.upgrade().unwrap().borrow_mut().next = self.next.clone();
}
pub fn add_tail(&mut self, pnew: &mut ListHead<T>) {
let prev = &mut self.prev;
unsafe {
let next = Weak::from_raw(self);
}
} }
} }

View File

@ -1,5 +1,5 @@
use std::rc::Rc; use std::rc::Rc;
use std::fs::File; //use std::fs::File;
use std::collections::HashMap; use std::collections::HashMap;
pub trait ProtoMsg { pub trait ProtoMsg {
@ -91,6 +91,7 @@ impl<T: Clone + ProtoMsg> MetaMgr<T> {
} }
pub fn load(&mut self) { pub fn load(&mut self) {
/*
for i in 0..self.meta_classes.len() { for i in 0..self.meta_classes.len() {
let meta = &self.meta_classes[i]; let meta = &self.meta_classes[i];
match File::open(&meta.file_name) { match File::open(&meta.file_name) {
@ -124,7 +125,7 @@ impl<T: Clone + ProtoMsg> MetaMgr<T> {
} }
} }
} }*/
} }
pub fn get_metalist(&mut self, idx: i32) -> Option<&Vec::<Rc::<T>>> { pub fn get_metalist(&mut self, idx: i32) -> Option<&Vec::<Rc::<T>>> {

View File

@ -1,17 +1,21 @@
pub struct TimerList {
}
pub struct Timer { pub struct Timer {
} }
impl Timer { impl Timer {
/* pub fn init(&mut self, pub fn init(&mut self,
get_tick_count: fn () -> i64, get_tick_count: fn () -> i64,
get_fxied_timer_expires: fn (i32, i64) -> i64, get_fxied_timer_expires: fn (i32, i64) -> i64,
context: (), context: (),
gctime: i32, gctime: i32,
cache_timer_num: i32) { cache_timer_num: i32) {
}*/ }
pub fn uninit(&mut self) { pub fn uninit(&mut self) {