diff --git a/src/env.rs b/src/env.rs index 9f63050a..07631017 100644 --- a/src/env.rs +++ b/src/env.rs @@ -15,6 +15,7 @@ pub trait Env: Sized + Clone + Default + PartialEq + Debug + Send + Sync + 'stat type ValidState: ValidState; type Message: 'static; //type Commit: Eq + Ord; + type Log: crate::log::Logger; } pub trait EnvFlexCtxHandler: Env { diff --git a/src/lib.rs b/src/lib.rs index 248cf3f6..9d33aaec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ pub mod util; pub mod validation; pub mod aliases; pub mod widgets; +pub mod log; pub(crate) use aliases::*; pub(crate) use backend::*; diff --git a/src/log/mod.rs b/src/log/mod.rs new file mode 100644 index 00000000..eba06a21 --- /dev/null +++ b/src/log/mod.rs @@ -0,0 +1,27 @@ +use std::error::Error; +use std::fmt::Arguments; + +use crate::env::Env; + +pub trait Logger { + //TODO static, Context, or extra immutable type shit which then needs to be added to every single fn + type LW: LogWriter; + + fn info(f: impl FnOnce(&mut Self::LW) -> R) -> R; + fn warn(f: impl FnOnce(&mut Self::LW) -> R) -> R; + fn debug(f: impl FnOnce(&mut Self::LW) -> R) -> R; + fn trace(f: impl FnOnce(&mut Self::LW) -> R) -> R; +} + +pub trait LogWriter { + type Err: Error; + + fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Self::Err>; +} + +fn akw(id: &E::WidgetID) +where + E: Env, +{ + E::Log::info(|w| write!(w, "{}: {:?}", "FuZ", id)).unwrap(); +}