1
This commit is contained in:
parent
1cb9fc8926
commit
e0ccc2ecc4
@ -3,6 +3,9 @@ name = "r9"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
#[lib]
|
||||||
|
#proc-macro = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -10,3 +13,5 @@ protobuf = "2.9.0"
|
|||||||
serde = "*"
|
serde = "*"
|
||||||
serde_derive = "*"
|
serde_derive = "*"
|
||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
|
syn = "1.0"
|
||||||
|
quote = "1.0"
|
@ -1,12 +1,3 @@
|
|||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
let result = 2 + 2;
|
|
||||||
assert_eq!(result, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod timer;
|
mod timer;
|
||||||
mod listhead;
|
mod listhead;
|
||||||
|
|
||||||
|
54
src/timer.rs
54
src/timer.rs
@ -3,6 +3,32 @@ use std::cell::RefCell;
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cmp;
|
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 TVN_BITS: usize = 6;
|
||||||
const TVR_BITS: usize = 8;
|
const TVR_BITS: usize = 8;
|
||||||
const TVN_SIZE: usize = 1 << TVN_BITS;
|
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(Default)]
|
||||||
|
//#[derive(crate::EnableSharedFromSelf)]
|
||||||
pub struct TimerList {
|
pub struct TimerList {
|
||||||
holder: TimerListRp,
|
holder: TimerListRp,
|
||||||
wp: Rc::<TimerListRp>,
|
wp: Rc::<TimerListRp>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user