This commit is contained in:
aozhiwei 2023-10-26 21:05:15 +08:00
parent 1cb9fc8926
commit e0ccc2ecc4
3 changed files with 59 additions and 9 deletions

View File

@ -3,6 +3,9 @@ name = "r9"
version = "0.1.0"
edition = "2021"
#[lib]
#proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@ -10,3 +13,5 @@ protobuf = "2.9.0"
serde = "*"
serde_derive = "*"
serde_json = "*"
syn = "1.0"
quote = "1.0"

View File

@ -1,12 +1,3 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
mod timer;
mod listhead;

View File

@ -3,6 +3,32 @@ 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;
use syn;
*/
const TVN_BITS: usize = 6;
const TVR_BITS: usize = 8;
const TVN_SIZE: usize = 1 << TVN_BITS;
@ -41,8 +67,36 @@ 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)]
pub struct TimerList {
holder: TimerListRp,
wp: Rc::<TimerListRp>,