This commit is contained in:
aozhiwei 2023-10-28 10:07:18 +08:00
parent 271b788e1f
commit afb739327f
3 changed files with 11 additions and 56 deletions

View File

@ -14,4 +14,7 @@ serde = "*"
serde_derive = "*"
serde_json = "*"
syn = "1.0"
quote = "1.0"
quote = "1.0"
r9_macro = { path = "../../third_party/r9_macro" }
r9_macro_derive = { path = "../../third_party/r9_macro_derive" }

View File

@ -1,7 +1,10 @@
use std::rc::{Rc, Weak};
use std::cell::RefCell;
use r9_macro::SharedFromSelf;
use r9_macro_derive::SharedFromSelf;
#[derive(Default)]
#[derive(SharedFromSelf)]
pub struct ListHead<T> {
prev: Weak::<RefCell::<ListHead<T>>>,
next: Weak::<RefCell::<ListHead<T>>>,
@ -13,10 +16,10 @@ impl<T> ListHead<T> {
pub fn new_head() -> Rc::<RefCell::<ListHead<T>>> {
let this = Rc::new(RefCell::new(ListHead{
prev: Weak::<RefCell::<ListHead<T>>>::new(),
next: Weak::<RefCell::<ListHead<T>>>::new(),
data: Weak::<RefCell::<T>>::new(),
_self_wp: Weak::<RefCell::<ListHead<T>>>::new()
prev: Default::default(),
next: Default::default(),
data: Default::default(),
_self_wp: Default::default(),
}));
this.borrow_mut()._self_wp = Rc::downgrade(&this);
this.borrow_mut().init();
@ -34,10 +37,6 @@ impl<T> ListHead<T> {
return this;
}
fn shared_from_self(&self) -> Rc::<RefCell::<ListHead<T>>> {
return self._self_wp.upgrade().unwrap();
}
fn init(&mut self) {
self.prev = Rc::downgrade(&self.shared_from_self());
self.next = Rc::downgrade(&self.shared_from_self());

View File

@ -3,26 +3,6 @@ use std::cell::RefCell;
use std::any::Any;
use std::cmp;
#[macro_export]
macro_rules! my_vec {
// 没带任何参数的 my_vec我们创建一个空的 vec
() => {
std::vec::Vec::new()
};
// 处理 my_vec![1, 2, 3, 4]
($($el:expr),*) => ({
let mut v = std::vec::Vec::new();
$(v.push($el);)*
v
});
// 处理 my_vec![0; 10]
($el:expr; $n:expr) => {
std::vec::from_elem($el, $n)
}
}
/*
use proc_macro::TokenStream;
use quote::quote;
@ -67,33 +47,6 @@ impl Default for TimerType {
}
}
/*
pub trait EnableSharedFromSelf {
fn shared_from_self();
}
#[proc_macro_derive(crate::EnableSharedFromSelf)]
pub fn hello_macro_derive(input: TokenStream) -> TokenStream {
// Construct a representation of Rust code as a syntax tree
// that we can manipulate
let ast = syn::parse(input).unwrap();
// Build the trait implementation
impl_hello_macro(&ast)
}
fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
let gen = quote! {
impl HelloMacro for #name {
fn hello_macro() {
println!("Hello, Macro! My name is {}!", stringify!(#name));
}
}
};
gen.into()
}
*/
#[derive(Default)]
//#[derive(crate::EnableSharedFromSelf)]