#report #traits #generate #generate-report

generate-report-trait

A minimal crate providing a trait for generating reports

1 unstable release

new 0.1.0 Feb 9, 2025

#144 in #report

Download history 106/week @ 2025-02-04

106 downloads per month
Used in workspacer

MIT/Apache

4KB

Generate Report

generate-report is a minimal crate that defines a trait for generating reports. The trait, GenerateReport, allows you to standardize report creation by specifying associated types for the report output and any errors that might occur during report generation.

Features

  • Lightweight Interface: A single trait that you can implement for your own types.
  • Flexible: Use associated types to tailor the report and error types to your application.
  • Easy Integration: Designed to fit into larger systems that require a reporting interface.

Usage

Add generate-report to your Cargo.toml dependencies:

[dependencies]
generate-report = "0.1.0"

Implement the trait for your custom type:

use generate_report::GenerateReport;

struct MyReporter;

#[derive(Debug)]
enum MyError {
    ReportError(String),
}

impl GenerateReport for MyReporter {
    type Report = String;
    type Error = MyError;

    fn generate_report(&self) -> Result<Self::Report, Self::Error> {
        // Generate and return your report here.
        Ok("This is my generated report".to_string())
    }
}

fn main() {
    let reporter = MyReporter;
    match reporter.generate_report() {
        Ok(report) => println!("Generated report: {}", report),
        Err(e) => eprintln!("Error generating report: {:?}", e),
    }
}

License

This project is dual-licensed under either the MIT license or the Apache License, Version 2.0, at your option.

Contributing

Contributions are welcome! Please check out the repository for details.

No runtime deps