From c22ee46299d1030ff745d604100d5067c769e510 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 29 Oct 2023 10:11:51 +0000 Subject: [PATCH] 1 --- f9/src/app.rs | 4 ++-- f9/src/timer.rs | 2 +- r9/src/xtimer.rs | 2 +- r9_macro/src/lib.rs | 1 - r9_macro_derive/src/lib.rs | 7 ++++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/f9/src/app.rs b/f9/src/app.rs index 6264a35..6e9d604 100644 --- a/f9/src/app.rs +++ b/f9/src/app.rs @@ -1,7 +1,7 @@ use std::rc::{Rc, Weak}; use std::cell::RefCell; use std::thread::sleep; -use std::time::{Duration, SystemTime}; +use std::time::Duration; use r9_macro::SharedFromSelf; use r9_macro_derive::SharedFromSelf; @@ -60,7 +60,7 @@ impl App { } pub fn run(&mut self) { - while true { + loop { crate::Timer::instance().borrow_mut().update(); sleep(Duration::from_secs(1)); } diff --git a/f9/src/timer.rs b/f9/src/timer.rs index 7b6b354..d87293b 100644 --- a/f9/src/timer.rs +++ b/f9/src/timer.rs @@ -1,7 +1,7 @@ use std::rc::{Rc, Weak}; use std::any::Any; use std::cell::RefCell; -use std::time::{Duration, Instant}; +use std::time::{Instant}; use r9::xtimer::{TimerCb, XTimerWp, XTimerAttacherRp, TimerEvent}; use r9_macro::SharedFromSelf; use r9_macro_derive::SharedFromSelf; diff --git a/r9/src/xtimer.rs b/r9/src/xtimer.rs index 956afe6..e1e341c 100644 --- a/r9/src/xtimer.rs +++ b/r9/src/xtimer.rs @@ -2,7 +2,7 @@ use std::rc::{Rc, Weak}; use std::cell::RefCell; use std::any::Any; use std::cmp; -use std::time::{Duration, Instant}; +use std::time::{Instant}; use r9_macro::SharedFromSelf; use r9_macro_derive::SharedFromSelf; diff --git a/r9_macro/src/lib.rs b/r9_macro/src/lib.rs index ad1da38..819424e 100644 --- a/r9_macro/src/lib.rs +++ b/r9_macro/src/lib.rs @@ -15,5 +15,4 @@ pub trait SharedFromSelf { } pub trait Singleton { - fn instance() -> Rc::>; } diff --git a/r9_macro_derive/src/lib.rs b/r9_macro_derive/src/lib.rs index 6b90edf..28520d4 100644 --- a/r9_macro_derive/src/lib.rs +++ b/r9_macro_derive/src/lib.rs @@ -42,10 +42,10 @@ pub fn singleton_derive(input: TokenStream) -> TokenStream { fn impl_singleton_macro(ast: &syn::DeriveInput) -> TokenStream { let name = &ast.ident; - let (impl_generics, _, _) = ast.generics.split_for_impl(); + let (_, _, _) = ast.generics.split_for_impl(); let gen = quote! { - impl #impl_generics Singleton for #name #impl_generics { - fn instance() -> Rc::> { + impl #name { + pub fn instance() -> Rc::> { static mut _INSTANCE: Option>> = None; unsafe { match &_INSTANCE { @@ -63,5 +63,6 @@ fn impl_singleton_macro(ast: &syn::DeriveInput) -> TokenStream { } } }; + //println!("{}", gen); gen.into() }