Report

Struct Report 

Source
pub struct Report<Context: ?Sized + 'static = Dynamic, Ownership: 'static = Mutable, ThreadSafety: 'static = SendSync> { /* private fields */ }
Expand description

An error report that contains a context, child reports, and attachments.

Report is the main type for creating and working with error reports in this library. It can contain a root context (typically an error), zero or more child reports, and zero or more attachments.

§Type Parameters

Report has three type parameters that control its behavior:

  • Context (C): The type of the root error or context (defaults to Dynamic)
  • Ownership (O): Controls whether the report can be cloned
    • Mutable: Unique ownership, can modify but cannot clone (default)
    • Cloneable: Shared ownership via Arc, can clone but cannot modify root
  • Thread Safety (T): Controls whether the report can be sent across threads
    • SendSync: Can be sent across threads (default, requires all data is Send+Sync)
    • Local: Cannot be sent across threads (allows non-thread-safe data)

§Common Usage

The easiest way to create a Report is with the report!() macro:

let report: Report = report!("file missing");
println!("{report}");

You can add context and attachments using method chaining:

let report = report!("database query failed")
    .context("failed to fetch user data")
    .attach("user_id: 12345");
println!("{report}");

Implementations§

Source§

impl<C: Sized, T> Report<C, Mutable, T>

Source

pub fn new(context: C) -> Self
where C: ObjectMarkerFor<T> + Error,

Creates a new Report with the given context.

This method is generic over the thread safety marker T. The context will use the handlers::Error handler for formatting.

See also:

§Examples
let report_sendsync: Report<MyError, Mutable, SendSync> = Report::new(MyError);
let report_local: Report<MyError, Mutable, Local> = Report::new(MyError);
Source

pub fn new_custom<H>(context: C) -> Self
where C: ObjectMarkerFor<T>, H: ContextHandler<C>,

Creates a new Report with the given context and handler.

This method is generic over the thread safety marker T.

If you’re having trouble with type inference for the thread safety parameter, consider using Report::new_sendsync_custom or Report::new_local_custom instead.

§Examples
let report_sendsync: Report<MyError> = Report::new_custom::<handlers::Debug>(MyError);
let report_local: Report<MyError> = Report::new_custom::<handlers::Display>(MyError);
Source

pub fn from_parts<H>( context: C, children: ReportCollection<Dynamic, T>, attachments: ReportAttachments<T>, ) -> Self
where C: ObjectMarkerFor<T>, H: ContextHandler<C>,

Creates a new Report with the given context, children, and attachments.

This method processes hooks during report creation. If you want to skip hook processing, use Report::from_parts_unhooked instead.

§Examples
let report: Report<String, _, SendSync> = Report::from_parts::<handlers::Display>(
    "error".to_string(),
    ReportCollection::new(),
    ReportAttachments::new(),
);
Source

pub fn from_parts_unhooked<H>( context: C, children: ReportCollection<Dynamic, T>, attachments: ReportAttachments<T>, ) -> Self
where C: ObjectMarkerFor<T>, H: ContextHandler<C>,

Creates a new Report with the given context, children, and attachments without hook processing.

This method skips hook processing during report creation. If you want hooks to be processed, use Report::from_parts instead.

§Examples
let report: Report<String, _, SendSync> = Report::from_parts_unhooked::<handlers::Display>(
    "error".to_string(),
    ReportCollection::new(),
    ReportAttachments::new(),
);
Source

pub fn into_parts( self, ) -> (C, ReportCollection<Dynamic, T>, ReportAttachments<T>)

Decomposes the Report into its constituent parts.

Returns a tuple containing the context, the children collection and the attachments collection in that order. This is the inverse operation of Report::from_parts and Report::from_parts_unhooked.

This method can be useful when you need to:

  • Extract and modify individual components of a report
  • Rebuild a report with different components
  • Transfer components between different reports
  • Perform custom processing on specific parts

Note that to exactly reconstruct the original report, you will also need to use the same handler as was used for the original report.

§Examples
// Create a report with some children and attachments
let mut report: Report<String> = Report::from_parts::<handlers::Display>(
    "main error".to_string(),
    ReportCollection::new(),
    ReportAttachments::new(),
);

// Add some content
let child_report = report!("child error").into_dynamic().into_cloneable();
report.children_mut().push(child_report);
report.attachments_mut().push("debug info".into());

// Decompose into parts
let (context, children, attachments) = report.into_parts();

assert_eq!(context, "main error");
assert_eq!(children.len(), 1);
assert!(attachments.len() >= 1); // "debug info" + potential automatic attachments

// Can rebuild with the same or different parts
let rebuilt: Report<String> = Report::from_parts::<handlers::Display>(
    context,
    children,
    attachments,
);
Source

pub fn into_current_context(self) -> C

Extracts and returns the context value from the Report.

This is a convenience method that consumes the Report and returns only the context, discarding the children and attachments. It’s equivalent to calling report.into_parts().0.

This method can be useful when:

  • You only need the underlying error or context value
  • Converting from a Report back to the original error type
  • Extracting context for logging or forwarding to other systems
  • Implementing error conversion traits
§Examples
#[derive(Debug, PartialEq, Clone)]
struct MyError {
    message: String,
    code: u32,
}

impl std::fmt::Display for MyError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Error {}: {}", self.code, self.message)
    }
}

// Create a report with a custom error context
let original_error = MyError {
    message: "database connection failed".to_string(),
    code: 500,
};
let report: Report<MyError> = report!(original_error.clone());

// Extract just the context, discarding report structure
let extracted_error = report.into_current_context();
assert_eq!(extracted_error, original_error);
assert_eq!(extracted_error.code, 500);
assert_eq!(extracted_error.message, "database connection failed");
Source

pub fn current_context_mut(&mut self) -> &mut C

Returns a mutable reference to the current context.

§Examples
use rootcause::prelude::*;
let mut report: Report<String> = report!(String::from("An error occurred"));
let context: &mut String = report.current_context_mut();
context.push_str(" and that's bad");
Source

pub fn context_transform<F, D>(self, f: F) -> Report<D, Mutable, T>
where F: FnOnce(C) -> D, D: ObjectMarkerFor<T> + Display + Debug,

Transforms the context type by applying a function, preserving report structure.

Converts the context type in-place without creating new nodes. Children, attachments, and hook data (backtraces, locations) are preserved.

§Examples
enum AppError {
    Lib(LibError)
}

let lib_report: Report<LibError> = report!(LibError);
let app_report: Report<AppError> = lib_report.context_transform(AppError::Lib);
§See Also
Source

pub fn context_transform_nested<F, D>(self, f: F) -> Report<D, Mutable, T>

Transforms the context and nests the original report as a preformatted child.

Creates a new parent node with fresh hook data (location, backtrace), but the original context type is lost—the child becomes PreformattedContext and cannot be downcast.

§Examples
enum AppError {
    Lib(LibError)
}

let lib_report: Report<LibError> = report!(LibError);
let app_report: Report<AppError> = lib_report.context_transform_nested(AppError::Lib);
§See Also
Source

pub fn preformat_root(self) -> (C, Report<PreformattedContext, Mutable, T>)

Extracts the context and returns it with a preformatted version of the report.

Returns a tuple: the original typed context and a new report with PreformattedContext containing the string representation. The preformatted report maintains the same structure (children and attachments). Useful when you need the typed value for processing and the formatted version for display.

This is a lower-level method primarily for custom transformation logic. Most users should use context_transform, context_transform_nested, or context_to instead.

See also: preformat (formats entire hierarchy), into_parts (extracts without formatting), current_context (reference without extraction).

§Examples
struct MyError {
    code: u32
}

let report: Report<MyError> = report!(MyError { code: 500 });
let (context, preformatted): (MyError, Report<PreformattedContext>) = report.preformat_root();
Source§

impl<C: ?Sized, T> Report<C, Mutable, T>

Source

pub fn as_mut(&mut self) -> ReportMut<'_, C, T>

Returns a mutable reference to the report.

§Examples
use rootcause::{ReportMut, prelude::*};
let mut report: Report = report!("error message");
let report_mut: ReportMut<'_> = report.as_mut();
Source

pub fn attach<A>(self, attachment: A) -> Self
where A: ObjectMarkerFor<T> + Display + Debug,

Adds a new attachment to the Report.

This is a convenience method used for chaining method calls; it consumes the Report and returns it.

If you want more direct control over the attachments, you can use the Report::attachments_mut.

§Examples
let report: Report = report!("error message");
let with_attachment = report.attach("additional info");
Source

pub fn attach_custom<H, A>(self, attachment: A) -> Self

Adds a new attachment to the Report.

This is a convenience method used for chaining method calls; it consumes the Report and returns it.

If you want more direct control over the attachments, you can use the Report::attachments_mut.

§Examples
let report: Report = report!("error message");
let with_attachment = report.attach_custom::<handlers::Display, _>("info");
Source

pub fn children_mut(&mut self) -> &mut ReportCollection<Dynamic, T>

Returns a mutable reference to the child reports.

§Examples
let mut report: Report = report!("error message");
let children_mut: &mut ReportCollection = report.children_mut();
Source

pub fn attachments_mut(&mut self) -> &mut ReportAttachments<T>

Returns a mutable reference to the attachments.

§Examples
let mut report: Report = report!("error message");
let attachments_mut: &mut ReportAttachments = report.attachments_mut();
Source§

impl<C: ?Sized, O, T> Report<C, O, T>

Source

pub fn context<D>(self, context: D) -> Report<D, Mutable, T>
where D: ObjectMarkerFor<T> + Display + Debug,

Creates a new Report with the given context and sets the current report as a child of the new report.

The new context will use the handlers::Display handler to format the context.

This is a convenience method used for chaining method calls; it consumes the Report and returns it.

If you want a different context handler, you can use Report::context_custom.

If you want to more directly control the allocation of the new report, you can use Report::from_parts, which is the underlying method used to implement this method.

§Examples
let report: Report = report!("initial error");
let contextual_report: Report<&str> = report.context("additional context");
Source

pub fn context_custom<H, D>(self, context: D) -> Report<D, Mutable, T>
where D: ObjectMarkerFor<T>, H: ContextHandler<D>,

Creates a new Report with the given context and sets the current report as a child of the new report.

This is a convenience method used for chaining method calls; it consumes the Report and returns it.

If you want to more directly control the allocation of the new report, you can use Report::from_parts, which is the underlying method used to implement this method.

§Examples
let report: Report = report!("initial error");
let contextual_report: Report<&str> = report.context_custom::<handlers::Debug, _>("context");
Source

pub fn context_to<D: ReportConversion<C, O, T>>(self) -> Report<D, Mutable, T>

Converts this report to a different context type using ReportConversion.

Implement ReportConversion once to define conversion logic, then use context_to() at call sites. Useful for consistent error type coercion across your codebase, especially when integrating with external libraries. You typically need to specify the target type (::<Type>).

See also: context_transform for direct conversion, context_transform_nested for wrapping, examples/thiserror_interop.rs for integration patterns.

§Examples
enum AppError { Parse }
impl<T> ReportConversion<std::num::ParseIntError, Mutable, T> for AppError
  where AppError: markers::ObjectMarkerFor<T>
{
    fn convert_report(report: Report<std::num::ParseIntError, Mutable, T>) -> Report<Self, Mutable, T>
    {
        report.context(AppError::Parse)
    }
}
// After implementing ReportConversion, use at call sites:
let result: Result<i32, Report<AppError>> = "abc".parse::<i32>().context_to();
Source

pub fn children(&self) -> &ReportCollection<Dynamic, T>

Returns a reference to the child reports.

§Examples
let report: Report = report!("error message");
let children: &ReportCollection = report.children();
assert_eq!(children.len(), 0); // The report has just been created, so it has no children
Source

pub fn attachments(&self) -> &ReportAttachments<T>

Returns a reference to the attachments.

§Examples
let report: Report = report!("error message");
let attachments: &ReportAttachments = report.attachments();
Source

pub fn into_dynamic(self) -> Report<Dynamic, O, T>

Changes the context type of the Report to Dynamic.

Calling this method is equivalent to calling report.into(), however this method has been restricted to only change the context mode to Dynamic.

This method can be useful to help with type inference or to improve code readability, as it more clearly communicates intent.

This method does not actually modify the report in any way. It only has the effect of “forgetting” that the context actually has the type C.

To get back the report with a concrete C you can use the method Report::downcast_report.

§Examples
let report: Report<MyError> = report!(my_error);
let dyn_report: Report<Dynamic> = report.into_dynamic();
Source

pub fn into_cloneable(self) -> Report<C, Cloneable, T>

Changes the ownership of the Report to Cloneable.

Calling this method is equivalent to calling report.into(), however this method has been restricted to only change the ownership mode to Cloneable.

This method can be useful to help with type inference or to improve code readability, as it more clearly communicates intent.

This method does not actually modify the report in any way. It only has the effect of “forgetting” that the Report only has a single owner.

After calling this method, you can clone the Report, but you can no longer add attachments to the Report or otherwise modify the root node.

To get back a Mutable you need to either:

§Examples
let report: Report<_, Mutable> = report!(my_error);
let cloneable_report: Report<_, Cloneable> = report.into_cloneable();
let cloned = cloneable_report.clone();
Source

pub fn into_local(self) -> Report<C, O, Local>

Changes the thread safety mode of the Report to Local.

Calling this method is equivalent to calling report.into(), however this method has been restricted to only change the thread safety mode to Local.

This method can be useful to help with type inference or to improve code readability, as it more clearly communicates intent.

This method does not actually modify the report in any way. It only has the effect of “forgetting” that all objects in the Report might actually be Send and Sync.

After calling this method, you can add objects to the Report that are neither Send nor Sync, but the report itself will no longer be Send+Sync.

§Examples
let report: Report<_, _, SendSync> = report!(my_error);
let local_report: Report<_, _, Local> = report.into_local();
Source

pub fn try_into_mutable(self) -> Result<Report<C, Mutable, T>, Report<C, O, T>>

Checks if there is only a single unique owner of the root node of the Report.

If there is only a single unique owner, this method marks the current Report as Mutable and returns Ok, otherwise it returns Err with the original Report.

This method does not actually modify the report in any way. It only has the effect of checking for unique ownership and returns the same report (with different type parameters) no matter the outcome of the check.

§Examples
let cloneable: Report<_, Cloneable> = some_report;
match cloneable.try_into_mutable() {
    Ok(mutable) => println!("Converted to mutable"),
    Err(cloneable) => println!("Still cloneable"),
}
Source

pub fn as_ref(&self) -> ReportRef<'_, C, O::RefMarker, T>

Returns an immutable reference to the report.

§Examples
let report: Report<_, Mutable> = report!("error message");
let report_ref: ReportRef<'_, _, Uncloneable> = report.as_ref();

let report: Report<_, Cloneable> = report!("error message").into_cloneable();
let report_ref: ReportRef<'_, _, Cloneable> = report.as_ref();
Source

pub fn iter_reports(&self) -> ReportIter<'_, O::RefMarker, T>

Returns an iterator over the complete report hierarchy including this report.

The iterator visits reports in a depth-first order: it first visits the current report, then recursively visits each child report and all of their descendants before moving to the next sibling. Unlike Report::iter_sub_reports, this method includes the report on which it was called as the first item in the iteration.

The ownership marker of the returned iterator references matches the ownership of this report. For mutable reports, the references may not be cloneable, which can limit how you can use them. If you need cloneable references, consider using Report::iter_sub_reports instead, which only iterates over children but guarantees cloneable references.

See also: Report::iter_sub_reports for iterating only over child reports with cloneable references.

§Examples
// Create base reports
let error1: Report = report!("error 1");
let error2: Report = report!("error 2");

// Build hierarchy using .context() which creates new nodes
let with_context1 = error1.context("context for error 1");  // Creates new node with error1 as child
let with_context2 = error2.context("context for error 2");  // Creates new node with error2 as child

// Create root that contains both context nodes as children
let mut root = report!("root error").context("context for root error");
root.children_mut().push(with_context1.into_dynamic().into_cloneable());
root.children_mut().push(with_context2.into_dynamic().into_cloneable());

// At this point our report tree looks like this:
// - context for root error
//   - root error
//   - context for error 1
//     - error 1
//   - context for error 2
//     - error 2

let all_reports: Vec<String> = root
    .iter_reports()
    .map(|report| report.format_current_context().to_string())
    .collect();

assert_eq!(all_reports[0], "context for root error");  // Current report is included
assert_eq!(all_reports[1], "root error");
assert_eq!(all_reports.len(), 6);
Source

pub fn iter_sub_reports(&self) -> ReportIter<'_, Cloneable, T>

Returns an iterator over child reports in the report hierarchy (excluding this report).

The iterator visits reports in a depth-first order: it first visits the current report’s children, then recursively visits each child report and all of their descendants before moving to the next sibling. Unlike Report::iter_reports, this method does NOT include the report on which it was called - only its descendants.

This method always returns cloneable report references, making it suitable for scenarios where you need to store or pass around the report references. This is different from Report::iter_reports, which returns references that match the ownership marker of the current report and may not be cloneable for mutable reports.

See also: Report::iter_reports for iterating over all reports including the current one.

§Examples
// Create base reports
let error1: Report = report!("error 1");
let error2: Report = report!("error 2");

// Build hierarchy using .context() which creates new nodes
let with_context1 = error1.context("context for error 1");  // Creates new node with error1 as child
let with_context2 = error2.context("context for error 2");  // Creates new node with error2 as child

// Create root that contains both context nodes as children
let mut root = report!("root error").context("context for root error");
root.children_mut().push(with_context1.into_dynamic().into_cloneable());
root.children_mut().push(with_context2.into_dynamic().into_cloneable());

let sub_reports: Vec<String> = root
    .iter_sub_reports()  // Note: using iter_sub_reports, not iter_reports
    .map(|report| report.format_current_context().to_string())
    .collect();

// Current "root" report is NOT included in the results
assert_eq!(sub_reports[0], "root error");
assert_eq!(sub_reports[1], "context for error 1");
assert_eq!(sub_reports.len(), 5);
Source

pub fn preformat(&self) -> Report<PreformattedContext, Mutable, SendSync>

Creates a new report, which has the same structure as the current report, but has all the contexts and attachments preformatted.

This can be useful, as the new report is mutable because it was just created, and additionally the new report is Send+Sync.

§Examples
let mut report: Report<NonSendSyncError, Mutable, Local> = report!(non_send_sync_error);
let preformatted: Report<PreformattedContext, Mutable, SendSync> = report.preformat();
assert_eq!(format!("{report}"), format!("{preformatted}"));
Source

pub fn current_context_type_id(&self) -> TypeId

Returns the TypeId of the current context.

§Examples
let report: Report<MyError> = report!(MyError);
let type_id = report.current_context_type_id();
assert_eq!(type_id, TypeId::of::<MyError>());

let report: Report<Dynamic> = report.into_dynamic();
let type_id = report.current_context_type_id();
assert_eq!(type_id, TypeId::of::<MyError>());
Source

pub fn current_context_type_name(&self) -> &'static str

Returns the core::any::type_name of the current context.

§Examples
let report: Report<MyError> = report!(MyError);
let type_name = report.current_context_type_name();
assert_eq!(type_name, core::any::type_name::<MyError>());

let report: Report<Dynamic> = report.into_dynamic();
let type_name = report.current_context_type_name();
assert_eq!(type_name, core::any::type_name::<MyError>());
Source

pub fn current_context_handler_type_id(&self) -> TypeId

Returns the TypeId of the handler used for the current context.

This can be useful for debugging or introspection to understand which handler was used to format the context.

§Examples
let report = Report::new_sendsync_custom::<handlers::Debug>("error message");
let handler_type = report.current_context_handler_type_id();
assert_eq!(handler_type, TypeId::of::<handlers::Debug>());
Source

pub fn current_context_error_source(&self) -> Option<&(dyn Error + 'static)>

Returns the error source if the context implements Error.

§Examples
let report: Report = report!("error message");
let source: Option<&dyn core::error::Error> = report.current_context_error_source();
assert!(source.is_none()); // The context does not implement Error, so no source

#[derive(Debug, thiserror::Error)]
enum MyError {
    #[error("Io error: {0}")]
    Io(#[from] std::io::Error),
    // ...
}

let report: Report<MyError> = report!(MyError::Io(std::io::Error::other("My inner error")));
let source: Option<&dyn std::error::Error> = report.current_context_error_source();
assert_eq!(format!("{}", source.unwrap()), "My inner error");
Source

pub fn format_current_context(&self) -> impl Display + Debug

Formats the current context with hook processing.

§Examples
let report: Report = report!("error message");
let formatted = report.format_current_context();
println!("{formatted}");
Source

pub fn format_current_context_unhooked(&self) -> impl Display + Debug

Formats the current context without hook processing.

§Examples
let report: Report = report!("error message");
let formatted = report.format_current_context_unhooked();
println!("{formatted}");
Source

pub fn format_with<H>(&self, hook: &H) -> impl Display + Debug
where H: ReportFormatter,

Formats the entire report using a specific report formatting hook.

This method allows you to format a report with a custom formatter without globally registering it. This is useful for:

  • One-off custom formatting
  • Testing different formatters
  • Using different formatters in different parts of your application

Unlike the default Display and Debug implementations which use the globally registered hook, this method uses the hook you provide directly.

§Examples
use rootcause::{hooks::builtin_hooks::report_formatter::DefaultReportFormatter, prelude::*};

let report = report!("error message");

// Format with ASCII-only output (no Unicode or ANSI colors)
let formatted = report.format_with(&DefaultReportFormatter::ASCII);
println!("{}", formatted);
Source

pub fn preferred_context_formatting_style( &self, report_formatting_function: FormattingFunction, ) -> ContextFormattingStyle

Gets the preferred formatting style for the context with hook processing.

§Arguments
  • report_formatting_function: Whether the report in which this context will be embedded is being formatted using Display formatting or Debug

See also Report::preferred_context_formatting_style_unhooked.

§Examples
let report: Report = report!("error message");
let style = report.preferred_context_formatting_style(handlers::FormattingFunction::Display);
Source

pub fn preferred_context_formatting_style_unhooked( &self, report_formatting_function: FormattingFunction, ) -> ContextFormattingStyle

Gets the preferred formatting style for the context without hook processing.

§Arguments
  • report_formatting_function: Whether the report in which this context will be embedded is being formatted using Display formatting or Debug
§Examples
let report: Report = report!("error message");
let style =
    report.preferred_context_formatting_style_unhooked(handlers::FormattingFunction::Display);
Source

pub fn strong_count(&self) -> usize

Returns the number of references to this report.

§Examples
let report: Report = report!("error message");
assert_eq!(report.strong_count(), 1); // We just created the report so it has a single owner
Source§

impl<C: Sized, O, T> Report<C, O, T>

Source

pub fn current_context(&self) -> &C

Returns a reference to the current context.

§Examples
let report: Report<MyError> = report!(my_error);
let context: &MyError = report.current_context();
Source§

impl<O, T> Report<Dynamic, O, T>

Source

pub fn downcast_current_context<C>(&self) -> Option<&C>
where C: Sized + 'static,

Attempts to downcast the current context to a specific type.

Returns Some(&C) if the current context is of type C, otherwise returns None.

§Examples
let report: Report<MyError> = report!(MyError);
let dyn_report: Report<Dynamic> = report.into_dynamic();
let context: Option<&MyError> = dyn_report.downcast_current_context();
assert!(context.is_some());
Source

pub unsafe fn downcast_current_context_unchecked<C>(&self) -> &C
where C: Sized + 'static,

Downcasts the current context to a specific type without checking.

§Safety

The caller must ensure:

  1. The current context is actually of type C (can be verified by calling current_context_type_id() first)
§Examples
let report: Report<MyError> = report!(MyError);
let dyn_report: Report = report.into_dynamic();

// Verify the type first
if dyn_report.current_context_type_id() == TypeId::of::<MyError>() {
    // SAFETY: We verified the type matches
    let context: &MyError = unsafe { dyn_report.downcast_current_context_unchecked() };
}
Source

pub fn downcast_report<C>(self) -> Result<Report<C, O, T>, Self>
where C: Sized + 'static,

Attempts to downcast the report to a specific context type.

Returns Ok(report) if the current context is of type C, otherwise returns Err(self) with the original report.

§Examples
let report: Report<MyError> = report!(MyError);
let dyn_report: Report = report.into_dynamic();
let downcasted: Result<Report<MyError>, _> = dyn_report.downcast_report();
assert!(downcasted.is_ok());
Source

pub unsafe fn downcast_report_unchecked<C>(self) -> Report<C, O, T>
where C: Sized + 'static,

Downcasts the report to a specific context type without checking.

§Safety

The caller must ensure:

  1. The current context is actually of type C (can be verified by calling current_context_type_id() first)
§Examples
let report: Report<MyError> = report!(MyError);
let dyn_report: Report = report.into_dynamic();

// Verify the type first
if dyn_report.current_context_type_id() == TypeId::of::<MyError>() {
    // SAFETY: We verified the type matches
    let downcasted: Report<MyError> = unsafe { dyn_report.downcast_report_unchecked() };
}
Source§

impl<C: Sized + Send + Sync> Report<C, Mutable, SendSync>

Source

pub fn new_sendsync(context: C) -> Self
where C: Error,

Creates a new Report with SendSync thread safety.

This is a convenience method that calls Report::new with explicit SendSync thread safety. Use this method when you’re having trouble with type inference for the thread safety parameter.

The context will use the handlers::Error handler to format the context.

§Examples
let report = Report::new_sendsync(MyError);
Source

pub fn new_sendsync_custom<H>(context: C) -> Self
where H: ContextHandler<C>,

Creates a new Report with SendSync thread safety and the given handler.

This is a convenience method that calls Report::new_custom with explicit SendSync thread safety. Use this method when you’re having trouble with type inference for the thread safety parameter.

§Examples
let report = Report::new_sendsync_custom::<handlers::Display>("error");
Source§

impl<C: Sized> Report<C, Mutable, Local>

Source

pub fn new_local(context: C) -> Self
where C: Error,

Creates a new Report with Local thread safety.

This is a convenience method that calls Report::new with explicit Local thread safety. Use this method when you’re having trouble with type inference for the thread safety parameter.

The context will use the handlers::Error handler to format the context.

§Examples
let report = Report::new_local(MyError);
Source

pub fn new_local_custom<H>(context: C) -> Self
where H: ContextHandler<C>,

Creates a new Report with Local thread safety and the given handler.

This is a convenience method that calls Report::new_custom with explicit Local thread safety. Use this method when you’re having trouble with type inference for the thread safety parameter.

§Examples
let report = Report::new_local_custom::<handlers::Display>("error");

Trait Implementations§

Source§

impl<C: ?Sized, T> Clone for Report<C, Cloneable, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: ?Sized, O, T> Debug for Report<C, O, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: ?Sized, O, T> Display for Report<C, O, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: ?Sized, O, T> Extend<Report<C, O, T>> for ReportCollection<C, T>

Source§

fn extend<I: IntoIterator<Item = Report<C, O, T>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<C: Sized, O, T> Extend<Report<C, O, T>> for ReportCollection<Dynamic, T>

Source§

fn extend<I: IntoIterator<Item = Report<C, O, T>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<C, T> From<C> for Report<C, Cloneable, T>
where C: ObjectMarkerFor<T> + Error + Sized,

Source§

fn from(context: C) -> Self

Converts to this type from the input type.
Source§

impl<C, T> From<C> for Report<C, Mutable, T>
where C: ObjectMarkerFor<T> + Error + Sized,

Source§

fn from(context: C) -> Self

Converts to this type from the input type.
Source§

impl<C, T> From<C> for Report<Dynamic, Cloneable, T>
where C: ObjectMarkerFor<T> + Error + Sized,

Source§

fn from(context: C) -> Self

Converts to this type from the input type.
Source§

impl<C, T> From<C> for Report<Dynamic, Mutable, T>
where C: ObjectMarkerFor<T> + Error + Sized,

Source§

fn from(context: C) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C>> for Report<Dynamic, Mutable, SendSync>

Source§

fn from(report: Report<C, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C>> for Report<C, Cloneable, SendSync>

Source§

fn from(report: Report<C, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C>> for Report<C, Cloneable, Local>

Source§

fn from(report: Report<C, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C>> for Report<C, Mutable, Local>

Source§

fn from(report: Report<C, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C>> for Report<Dynamic, Cloneable, SendSync>

Source§

fn from(report: Report<C, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C>> for Report<Dynamic, Cloneable, Local>

Source§

fn from(report: Report<C, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C>> for Report<Dynamic, Mutable, Local>

Source§

fn from(report: Report<C, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C, Cloneable>> for Report<C, Cloneable, Local>

Source§

fn from(report: Report<C, Cloneable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C, Cloneable>> for Report<Dynamic, Cloneable, SendSync>

Source§

fn from(report: Report<C, Cloneable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C, Cloneable>> for Report<Dynamic, Cloneable, Local>

Source§

fn from(report: Report<C, Cloneable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C, Cloneable, Local>> for Report<Dynamic, Cloneable, Local>

Source§

fn from(report: Report<C, Cloneable, Local>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C, Mutable, Local>> for Report<C, Cloneable, Local>

Source§

fn from(report: Report<C, Mutable, Local>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C, Mutable, Local>> for Report<Dynamic, Cloneable, Local>

Source§

fn from(report: Report<C, Mutable, Local>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<Report<C, Mutable, Local>> for Report<Dynamic, Mutable, Local>

Source§

fn from(report: Report<C, Mutable, Local>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O> From<Report<C, O>> for Box<dyn Error + Send + Sync>

Source§

fn from(report: Report<C, O, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O> From<Report<C, O>> for Error

Available on crate feature compat-anyhow1 only.
Source§

fn from(report: Report<C, O, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O> From<Report<C, O>> for Report

Available on crate feature compat-eyre06 only.
Source§

fn from(report: Report<C, O, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O> From<Report<C, O>> for Report<ReportAsError<C>>

Available on crate feature compat-error-stack05 only.
Source§

fn from(report: Report<C, O, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O> From<Report<C, O>> for Report<ReportAsError<C>>

Available on crate feature compat-error-stack06 only.
Source§

fn from(report: Report<C, O, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O> From<Report<C, O, Local>> for Box<dyn Error>

Source§

fn from(report: Report<C, O, Local>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O, T> From<Report<C, O, T>> for ReportAsError<C, T>

Source§

fn from(value: Report<C, O, T>) -> Self

Converts to this type from the input type.
Source§

impl From<Report<Dynamic, Cloneable>> for Report<Dynamic, Cloneable, Local>

Source§

fn from(report: Report<Dynamic, Cloneable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl From<Report<Dynamic, Mutable, Local>> for Report<Dynamic, Cloneable, Local>

Source§

fn from(report: Report<Dynamic, Mutable, Local>) -> Self

Converts to this type from the input type.
Source§

impl From<Report> for Report<Dynamic, Cloneable, SendSync>

Source§

fn from(report: Report<Dynamic, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl From<Report> for Report<Dynamic, Cloneable, Local>

Source§

fn from(report: Report<Dynamic, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl From<Report> for Report<Dynamic, Mutable, Local>

Source§

fn from(report: Report<Dynamic, Mutable, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<'a, C: ?Sized, T> From<ReportRef<'a, C, Cloneable, T>> for Report<C, Cloneable, T>

Source§

fn from(report: ReportRef<'a, C, Cloneable, T>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, O, T> FromIterator<Report<C, O, T>> for ReportCollection<C, T>

Source§

fn from_iter<I: IntoIterator<Item = Report<C, O, T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<C: Sized, O, T> FromIterator<Report<C, O, T>> for ReportCollection<Dynamic, T>

Source§

fn from_iter<I: IntoIterator<Item = Report<C, O, T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<C: ?Sized, O> IntoAnyhow for Report<C, O>

Available on crate feature compat-anyhow1 only.
Source§

type Output = Error

The type produced by the conversion. Read more
Source§

fn into_anyhow(self) -> Self::Output

Converts this value into an anyhow type. Read more
Source§

impl<C: ?Sized, O> IntoBoxedError for Report<C, O, SendSync>

Source§

type Output = Box<dyn Error + Send + Sync>

The type produced by the conversion. Read more
Source§

fn into_boxed_error(self) -> Self::Output

Converts this value into a boxed error type. Read more
Source§

impl<C: ?Sized, O> IntoBoxedError for Report<C, O, Local>

Source§

type Output = Box<dyn Error>

The type produced by the conversion. Read more
Source§

fn into_boxed_error(self) -> Self::Output

Converts this value into a boxed error type. Read more
Source§

impl<C: ?Sized, O> IntoErrorStack<C> for Report<C, O, SendSync>

Available on crate feature compat-error-stack05 only.
Source§

type Output = Report<ReportAsError<C>>

The type produced by the conversion. Read more
Source§

fn into_error_stack(self) -> Self::Output

Converts this value into an error-stack type. Read more
Source§

impl<C: ?Sized, O> IntoErrorStack<C> for Report<C, O, SendSync>

Available on crate feature compat-error-stack06 only.
Source§

type Output = Report<ReportAsError<C>>

The type produced by the conversion. Read more
Source§

fn into_error_stack(self) -> Self::Output

Converts this value into an error-stack type. Read more
Source§

impl<C: ?Sized, O> IntoEyre for Report<C, O>

Available on crate feature compat-eyre06 only.
Source§

type Output = Report

The type produced by the conversion. Read more
Source§

fn into_eyre(self) -> Self::Output

Converts this value into an eyre type. Read more
Source§

impl<C: ?Sized, O, T> IntoReport<Local> for Report<C, O, T>

Source§

type Context = C

The context type of the resulting report.
Source§

type Ownership = O

The ownership marker of the resulting report.
Source§

fn into_report(self) -> Report<Self::Context, Self::Ownership, Local>

Converts self into a Report with the specified thread-safety marker. Read more
Source§

impl<C: ?Sized, O> IntoReport<SendSync> for Report<C, O, SendSync>

Source§

type Context = C

The context type of the resulting report.
Source§

type Ownership = O

The ownership marker of the resulting report.
Source§

fn into_report(self) -> Report<Self::Context, Self::Ownership, SendSync>

Converts self into a Report with the specified thread-safety marker. Read more
Source§

impl<C, O, T> IntoReportCollection<Local> for Report<C, O, T>

Source§

type Context = C

The context type of the resulting report collection.
Source§

fn into_report_collection(self) -> ReportCollection<Self::Context, Local>

Converts self into a ReportCollection with the specified thread-safety marker. Read more
Source§

impl<C, O> IntoReportCollection<SendSync> for Report<C, O, SendSync>

Source§

type Context = C

The context type of the resulting report collection.
Source§

fn into_report_collection(self) -> ReportCollection<Self::Context, SendSync>

Converts self into a ReportCollection with the specified thread-safety marker. Read more
Source§

impl<C: ?Sized, O> Send for Report<C, O, SendSync>

Source§

impl<C: ?Sized, O> Sync for Report<C, O, SendSync>

Source§

impl<C: ?Sized, O, T> Unpin for Report<C, O, T>

Auto Trait Implementations§

§

impl<Context, Ownership, ThreadSafety> Freeze for Report<Context, Ownership, ThreadSafety>
where Context: ?Sized,

§

impl<Context, Ownership, ThreadSafety> RefUnwindSafe for Report<Context, Ownership, ThreadSafety>
where Context: RefUnwindSafe + ?Sized, Ownership: RefUnwindSafe, ThreadSafety: RefUnwindSafe,

§

impl<Context = Dynamic, Ownership = Mutable, ThreadSafety = SendSync> !Send for Report<Context, Ownership, ThreadSafety>

§

impl<Context = Dynamic, Ownership = Mutable, ThreadSafety = SendSync> !Sync for Report<Context, Ownership, ThreadSafety>

§

impl<Context, Ownership, ThreadSafety> UnwindSafe for Report<Context, Ownership, ThreadSafety>
where Context: UnwindSafe + ?Sized, Ownership: UnwindSafe, ThreadSafety: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<O> ObjectMarkerFor<Local> for O
where O: 'static,

Source§

impl<O> ObjectMarkerFor<SendSync> for O
where O: 'static + Send + Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> Attachment for T

Source§

impl<T> OpaqueAttachment for T
where T: Send + Sync + 'static,