[−][src]Type Definition fast_logger::Compatibility
type Compatibility = Box<dyn FnMut(u8, &'static str, Box<dyn Fn(&mut Formatter) -> Result + Send + Sync>)>;
Compatibility type when using loggers across library boundaries
Example
Here, the host as well as MyLibrary
can both use any logger they wish as they are decoupled
with respect to their loggers. The only bridge between them is the Compatibility type.
This is especially useful so a library can expose the compatibility type, while hosts of that library can pick and choose which logger to connect to it.
use fast_logger::*; fn main() { let mut logger = Logger::<Generic>::spawn(); type MyCompatibility = Box<dyn FnMut(u8, &'static str, Box<dyn Fn(&mut std::fmt::Formatter) -> std::fmt::Result + Send + Sync>)>; struct MyLibrary { log: Logpass, } impl MyLibrary { pub fn new(log: MyCompatibility) -> Self { Self { log: Logpass::from_compatibility(log), } } pub fn function(&mut self) { info![self.log, "tst", "Compatibility layer"]; } } let mut my_lib = MyLibrary::new(logger.to_compatibility()); my_lib.function(); }