Report

Struct Report 

Source
pub struct Report<T: Fn() -> String> { /* private fields */ }
Expand description

Group of logging events

This type should not be used directly, but through the macros report and log

Implementations§

Source§

impl Report<fn() -> String>

Source

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

pub fn warn(message: Arguments<'_>)

Logs a message with the warning prefix

§Example
use report::Report;

let data = 42;
Report::warn(format_args!("Warning: {data}"));
Source

pub fn error(message: Arguments<'_>)

Logs a message with the error prefix

§Example
use report::Report;

let data = 42;
Report::error(format_args!("Error: {data}"));
Source§

impl<T: Fn() -> String> Report<T>

Source

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);
Source

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§

Source§

impl<T: Fn() -> String> Drop for Report<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.