|
|
@ -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
|
|
|
|
pub mod bytes
|
|
|
|
{
|
|
|
|
{
|
|
|
|
use super::*;
|
|
|
|
use super::*;
|
|
|
@ -216,3 +276,4 @@ pub mod bytes
|
|
|
|
|
|
|
|
|
|
|
|
mod slice;
|
|
|
|
mod slice;
|
|
|
|
pub use slice::*;
|
|
|
|
pub use slice::*;
|
|
|
|
|
|
|
|
|
|
|
|