pub struct Report<T: Fn() -> String> { /* private fields */ }Expand description
Implementations§
Source§impl Report<fn() -> String>
impl Report<fn() -> String>
Sourcepub fn info(message: Arguments<'_>)
pub fn info(message: Arguments<'_>)
Logs a message with the info prefix
§Example
use report::Report;
let data = 42;
Report::info(format_args!("Data: {data}"));Source§impl<T: Fn() -> String> Report<T>
impl<T: Fn() -> String> Report<T>
Sourcepub fn log(message: T) -> Self
pub fn log(message: T) -> Self
Collects all nested logging events and prints them
When this report is dropped, it will be printed to stdout.
§Example
use report::{Report, info};
let report = Report::log(|| format!("Running task"));
info!("Complementary information");
drop(report);Sourcepub fn rec(message: T) -> Self
pub fn rec(message: T) -> Self
Collects all nested logging events and appends them to the preceding report
When this report is dropped and there are events available, its message will be formatted, and the events will be tagged with it.
§Example
use report::{Report, info};
let report = Report::rec(|| format!("Running task"));
info!("Complementary information");
drop(report);Examples found in repository?
examples/main.rs (line 10)
7fn main() {
8 let path = "data.txt";
9
10 #[report("Running task one on {path}")]
11 task_one(path).ok();
12
13 let path = "Cargo.toml";
14 #[report("Running task two on {path}")]
15 task_two(path).ok();
16}
17
18fn task_one(file: &str) -> Result {
19 let _file = File::open(file)?;
20 bail!("File exists, even though it should not")
21}
22
23#[report]
24fn task_two(file: &str) -> Result {
25 let file = File::open(file)?;
26 let metadata = file.metadata()?;
27
28 info!("File size: {}", metadata.len());
29
30 for line in BufReader::new(file).lines() {
31 #[report("Reading line")]
32 let line = line?;
33
34 if line.starts_with("[") {
35 info!("Found section: {line}");
36 }
37 }
38
39 Ok(())
40}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Report<T>where
T: Freeze,
impl<T> RefUnwindSafe for Report<T>where
T: RefUnwindSafe,
impl<T> Send for Report<T>where
T: Send,
impl<T> Sync for Report<T>where
T: Sync,
impl<T> Unpin for Report<T>where
T: Unpin,
impl<T> UnwindSafe for Report<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more