added optional logging

master
Avril 4 years ago
parent fb1096f9a3
commit 28da9e43fd
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -13,3 +13,4 @@ openssl = "0.10.33"
stackalloc = "1.1.0"
pin-project = "1.0.6"
bytes = "0.5.6"
log = {version = "0.4.14", optional=true}

@ -202,6 +202,66 @@ where F: FnOnce(&mut [u8]) -> T
}
#[macro_export] macro_rules! lazy_format {
($msg:literal $($tt:tt)*) => {
{
use ::std::fmt::{self, Write, Formatter};
use ::std::sync::Mutex;
use ::std::io;
let pfn = move |fmt| {
write!(fmt, $msg $($tt)*)?;
let mut sfmt = String::new();
write!(&mut sfmt, $msg $($tt)*)?;
Ok(sfmt)
};
enum LazyFormatInner<F>
{
//todo: redo this entire thing
Pending(F),
Complete(String),
Error(fmt::Error),
Panicked,
}
struct LazyFormat<F>(Mutex<LazyFormatInner<F>>);
impl<F: FnOnce(&mut fmt::Formatter<'_>) -> io::Result<String>> fmt::Display for LazyFormat<F>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
//todo: redo this entire thing
/*
let mut inner = self.0.lock().unwrap();
let this = std::mem::replace(inner, LazyFormatInner::Panicked);
//TODO: impl fmt::Write wrapper that multi-writes to 2 outputs
let string = match this {
LazyFormatInner::Pending(func) => func(f),
LazyFormatInner::Complete(string) => write!(f, "{}", string).map(move |_| string),
LazyFormatInner::Error(err) => return Err(err),
LazyFormatInner::Panicked => panic!(),
};
match string {
Err(err) => {
*inner = LazyFormatInner::Error(err),
},
}*/
}
}
}
}
}
#[cfg(not(feature="log"))] #[macro_export] macro_rules! trace {
($fmt:literal $($tt:tt)*) => {
{
((), $($tt)*);
}
}
}
pub mod bytes
{
use super::*;
@ -216,3 +276,4 @@ pub mod bytes
mod slice;
pub use slice::*;

@ -2,6 +2,7 @@
#![allow(dead_code)]
#[macro_use] extern crate pin_project;
#[cfg(feature="log")] #[macro_use] extern crate log;
// Extensions & macros
#[macro_use] mod ext;

Loading…
Cancel
Save