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
impl BugReportConfigBuilder
Sourcepub fn add_template(
self,
name: impl Into<String>,
template: IssueTemplate,
) -> Self
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 templatetemplate
- 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
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}
Sourcepub fn add_template_file(
self,
name: impl Into<String>,
template_file: TemplateFile,
) -> Self
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 filetemplate_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}
Sourcepub fn hyperlinks(self, mode: HyperlinkMode) -> Self
pub fn hyperlinks(self, mode: HyperlinkMode) -> Self
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}
Sourcepub fn build(self) -> Result<(), &'static str>
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 installedErr(&'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
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§
impl Freeze for BugReportConfigBuilder
impl RefUnwindSafe for BugReportConfigBuilder
impl Send for BugReportConfigBuilder
impl Sync for BugReportConfigBuilder
impl Unpin for BugReportConfigBuilder
impl UnwindSafe for BugReportConfigBuilder
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