BugReportConfigBuilder

Struct BugReportConfigBuilder 

Source
pub struct BugReportConfigBuilder { /* private fields */ }
Expand description

Builder for configuring the global bug reporting system (std only).

This builder allows you to add templates, configure hyperlink behavior, and build the global configuration. Once built, the configuration is stored globally and used by the bug! macro.

§Examples

use bug::{init, IssueTemplate, HyperlinkMode};
 
let builder = init("owner", "repo")
    .add_template("error", IssueTemplate::new("Error Report", "An error occurred"))
    .hyperlinks(HyperlinkMode::Auto);

Implementations§

Source§

impl BugReportConfigBuilder

Source

pub fn add_template( self, name: impl Into<String>, template: IssueTemplate, ) -> Self

Add an issue template to the configuration.

§Arguments
  • name - Name to identify the template
  • template - The issue template to add
§Examples
use bug::{init, IssueTemplate};
 
let builder = init("owner", "repo")
    .add_template("bug", IssueTemplate::new("Bug Report", "Found a bug"));
Examples found in repository?
examples/hyperlink_demo.rs (lines 6-9)
3fn main() -> Result<(), &'static str> {
4    // Initialize with auto-detection (default)
5    init("tristanpoland", "GLUE")
6        .add_template("demo", IssueTemplate::new(
7            "Demo Issue: {title}",
8            "This is a demo issue with title: {title}"
9        ))
10        .hyperlinks(HyperlinkMode::Auto) // This is the default
11        .build()?;
12
13    println!("Auto-detect hyperlinks mode:");
14    let _url1 = bug!("demo", {
15        title = "Hyperlink Demo"
16    });
17
18    Ok(())
19}
More examples
Hide additional examples
examples/basic_usage.rs (lines 8-11)
5fn main() -> Result<(), &'static str> {
6    // Initialize the bug reporter with your GitHub repo
7    init("tristanpoland", "GLUE")
8        .add_template("crash", IssueTemplate::new(
9            "Application Crash: {error_type}",
10            "## Description\nThe application crashed with error: {error_type}\n\n## Context\n- Function: {function}\n- Line: {line}\n- OS: {os}"
11        ).with_labels(vec!["bug".to_string(), "crash".to_string()]))
12        .add_template("performance", IssueTemplate::new(
13            "Performance Issue: {operation} is too slow",
14            "## Performance Problem\n\nOperation: {operation}\nExpected time: {expected}ms\nActual time: {actual}ms\n\n## Environment\nOS: {os}\nVersion: {version}"
15        ).with_labels(vec!["performance".to_string()]))
16        .build()?;
17
18    // Simulate different types of bugs
19    let crash_url = bug!("crash", {
20        error_type = "NullPointerException",
21        function = "calculate_sum",
22        line = "42",
23        os = std::env::consts::OS
24    });
25    
26    let perf_url = bug!("performance", {
27        operation = "database_query",
28        expected = 100,
29        actual = 1500,
30        os = std::env::consts::OS,
31        version = env!("CARGO_PKG_VERSION")
32    });
33
34    bug!("crash");
35
36    Ok(())
37}
Source

pub fn add_template_file( self, name: impl Into<String>, template_file: TemplateFile, ) -> Self

Add a template file to the configuration.

§Arguments
  • name - Name to identify the template file
  • template_file - The template file to add
§Examples
use bug::{init, TemplateFile};
 
let builder = init("owner", "repo")
    .add_template_file("crash", TemplateFile::new("Crash Report\nApp crashed"));
Examples found in repository?
examples/template_file_usage.rs (line 7)
5fn main() -> Result<(), &'static str> {
6    init("tristanpoland", "GLUE")
7        .add_template_file("crash", template_file!("../templates/crash_report.md", labels: ["bug", "crash"]))
8        .add_template_file("performance", template_file!("../templates/performance_issue.md", labels: ["performance", "optimization"]))
9        .build()?;
10
11    let crash_url = bug!("crash", {
12        error_type = "NullPointerException",
13        function = "calculate_sum",
14        line = "42",
15        os = std::env::consts::OS,
16        version = env!("CARGO_PKG_VERSION"),
17        step1 = "Open the application",
18        step2 = "Click on calculate button",
19        step3 = "Application crashes",
20        expected_behavior = "Should calculate the sum correctly",
21        additional_info = "This happens only on Windows 11"
22    });
23
24    let perf_url = bug!("performance", {
25        operation = "database_query",
26        expected = "100",
27        actual = "1500",
28        ratio = "15",
29        os = std::env::consts::OS,
30        version = env!("CARGO_PKG_VERSION"),
31        hardware = "Intel i7-12700K, 32GB RAM",
32        profiling_data = "CPU: 45%, Memory: 2.1GB, Disk I/O: 150MB/s",
33        impact_description = "User experience is significantly degraded"
34    });
35
36    Ok(())
37}

Configure hyperlink behavior for terminal output.

§Arguments
  • mode - How to handle hyperlinks in output
§Examples
use bug::{init, HyperlinkMode};
 
let builder = init("owner", "repo")
    .hyperlinks(HyperlinkMode::Always);
Examples found in repository?
examples/hyperlink_demo.rs (line 10)
3fn main() -> Result<(), &'static str> {
4    // Initialize with auto-detection (default)
5    init("tristanpoland", "GLUE")
6        .add_template("demo", IssueTemplate::new(
7            "Demo Issue: {title}",
8            "This is a demo issue with title: {title}"
9        ))
10        .hyperlinks(HyperlinkMode::Auto) // This is the default
11        .build()?;
12
13    println!("Auto-detect hyperlinks mode:");
14    let _url1 = bug!("demo", {
15        title = "Hyperlink Demo"
16    });
17
18    Ok(())
19}
Source

pub fn build(self) -> Result<(), &'static str>

Build and install the global configuration (std only).

This method finalizes the configuration and stores it globally. After calling this, the bug! macro can be used throughout the application.

§Returns
  • Ok(()) - Configuration was successfully installed
  • Err(&'static str) - Configuration was already initialized
§Examples
use bug::{init, IssueTemplate};
 
let result = init("owner", "repo")
    .add_template("bug", IssueTemplate::new("Bug", "Description"))
    .build();
assert!(result.is_ok() || result == Err("Bug reporting already initialized"));
Examples found in repository?
examples/hyperlink_demo.rs (line 11)
3fn main() -> Result<(), &'static str> {
4    // Initialize with auto-detection (default)
5    init("tristanpoland", "GLUE")
6        .add_template("demo", IssueTemplate::new(
7            "Demo Issue: {title}",
8            "This is a demo issue with title: {title}"
9        ))
10        .hyperlinks(HyperlinkMode::Auto) // This is the default
11        .build()?;
12
13    println!("Auto-detect hyperlinks mode:");
14    let _url1 = bug!("demo", {
15        title = "Hyperlink Demo"
16    });
17
18    Ok(())
19}
More examples
Hide additional examples
examples/template_file_usage.rs (line 9)
5fn main() -> Result<(), &'static str> {
6    init("tristanpoland", "GLUE")
7        .add_template_file("crash", template_file!("../templates/crash_report.md", labels: ["bug", "crash"]))
8        .add_template_file("performance", template_file!("../templates/performance_issue.md", labels: ["performance", "optimization"]))
9        .build()?;
10
11    let crash_url = bug!("crash", {
12        error_type = "NullPointerException",
13        function = "calculate_sum",
14        line = "42",
15        os = std::env::consts::OS,
16        version = env!("CARGO_PKG_VERSION"),
17        step1 = "Open the application",
18        step2 = "Click on calculate button",
19        step3 = "Application crashes",
20        expected_behavior = "Should calculate the sum correctly",
21        additional_info = "This happens only on Windows 11"
22    });
23
24    let perf_url = bug!("performance", {
25        operation = "database_query",
26        expected = "100",
27        actual = "1500",
28        ratio = "15",
29        os = std::env::consts::OS,
30        version = env!("CARGO_PKG_VERSION"),
31        hardware = "Intel i7-12700K, 32GB RAM",
32        profiling_data = "CPU: 45%, Memory: 2.1GB, Disk I/O: 150MB/s",
33        impact_description = "User experience is significantly degraded"
34    });
35
36    Ok(())
37}
examples/basic_usage.rs (line 16)
5fn main() -> Result<(), &'static str> {
6    // Initialize the bug reporter with your GitHub repo
7    init("tristanpoland", "GLUE")
8        .add_template("crash", IssueTemplate::new(
9            "Application Crash: {error_type}",
10            "## Description\nThe application crashed with error: {error_type}\n\n## Context\n- Function: {function}\n- Line: {line}\n- OS: {os}"
11        ).with_labels(vec!["bug".to_string(), "crash".to_string()]))
12        .add_template("performance", IssueTemplate::new(
13            "Performance Issue: {operation} is too slow",
14            "## Performance Problem\n\nOperation: {operation}\nExpected time: {expected}ms\nActual time: {actual}ms\n\n## Environment\nOS: {os}\nVersion: {version}"
15        ).with_labels(vec!["performance".to_string()]))
16        .build()?;
17
18    // Simulate different types of bugs
19    let crash_url = bug!("crash", {
20        error_type = "NullPointerException",
21        function = "calculate_sum",
22        line = "42",
23        os = std::env::consts::OS
24    });
25    
26    let perf_url = bug!("performance", {
27        operation = "database_query",
28        expected = 100,
29        actual = 1500,
30        os = std::env::consts::OS,
31        version = env!("CARGO_PKG_VERSION")
32    });
33
34    bug!("crash");
35
36    Ok(())
37}

Auto Trait Implementations§

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.