Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d3b96ec
.
Kile-Asmussen Mar 6, 2026
ee2934b
Examples
Kile-Asmussen Mar 6, 2026
e7a5abf
.
Kile-Asmussen Mar 7, 2026
07de1de
Merge branch 'rootcause-rs:main' into more-examples
Kile-Asmussen Mar 7, 2026
7d0604a
final examples
Kile-Asmussen Mar 11, 2026
697db1d
last example
Kile-Asmussen Mar 11, 2026
5bcb210
Update src/report_collection/owned.rs
Kile-Asmussen Mar 28, 2026
63b0d1c
Update src/report_attachment/mut_.rs
Kile-Asmussen Mar 28, 2026
e842306
Update src/report_attachment/owned.rs
Kile-Asmussen Mar 28, 2026
19115f0
Update src/report_attachment/ref_.rs
Kile-Asmussen Mar 28, 2026
a164dd1
Update src/report_attachment/mut_.rs
Kile-Asmussen Mar 28, 2026
cde73f0
Update src/report_attachment/ref_.rs
Kile-Asmussen Mar 28, 2026
202ec53
Update src/report_collection/owned.rs
Kile-Asmussen Mar 28, 2026
3f65670
Update src/report_collection/owned.rs
Kile-Asmussen Mar 28, 2026
0ff6ebf
.
Kile-Asmussen Mar 28, 2026
51ff36d
Update src/report_attachment/owned.rs
Kile-Asmussen Mar 28, 2026
92b0466
fixed missing doctest
Kile-Asmussen Mar 28, 2026
bb46b1f
Update src/report_attachment/owned.rs
Kile-Asmussen Mar 28, 2026
f429daf
Update src/report_attachment/owned.rs
Kile-Asmussen Mar 28, 2026
be3733a
Update src/report_attachment/owned.rs
Kile-Asmussen Mar 28, 2026
be5ca4f
Update src/report_attachment/owned.rs
Kile-Asmussen Mar 28, 2026
49a7d06
Example => Examples
Kile-Asmussen Mar 28, 2026
83277a0
oops
Kile-Asmussen Mar 28, 2026
c8c5adb
editing a few comments
Kile-Asmussen Mar 28, 2026
afe33e1
.
Kile-Asmussen Mar 29, 2026
1a306ce
Merge branch 'main' into more-examples
Kile-Asmussen Mar 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/.direnv
/.claude
4 changes: 2 additions & 2 deletions src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
//! - **Ergonomic APIs**: Use familiar Rust patterns like `From`/`Into` traits
//! and extension traits with descriptive method names
//!
//! # Example
//! # Examples
//!
//! Here's how to use the [`IntoRootcause`] trait to convert external errors:
//!
Expand Down Expand Up @@ -201,7 +201,7 @@ pub mod eyre06;
///
/// fn requires_error_trait(err: impl std::error::Error) {}
///
/// let report = Report::new_sendsync(std::io::Error::from(std::io::ErrorKind::NotFound));
/// let report: Report<std::io::Error> = Report::new_sendsync(std::io::Error::from(std::io::ErrorKind::NotFound));
/// let as_error = ReportAsError(report.into_cloneable());
/// requires_error_trait(as_error);
/// ```
Expand Down
6 changes: 3 additions & 3 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub use rootcause_internals::handlers::{
/// macro when you create a report from a type implementing `std::error::Error`.
/// You rarely need to specify it explicitly.
///
/// # Example
/// # Examples
///
/// ```
/// use std::io;
Expand Down Expand Up @@ -243,7 +243,7 @@ where
/// - **`source` method**: Always returns `None`
/// - **Preferred formatting**: Same as requested formatting of the report.
///
/// # Example
/// # Examples
///
/// ```
/// use rootcause::prelude::*;
Expand Down Expand Up @@ -322,7 +322,7 @@ where
/// - **Debug output**: "An object of type TypeName"
/// - **Source**: Always returns `None`
///
/// # Example
/// # Examples
///
/// ```
/// use rootcause::{handlers, prelude::*};
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/builtin_hooks/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl AttachmentHandler<Location> for LocationHandler {
/// captures the source location where each report is created and attaches
/// it as a [`Location`] attachment.
///
/// ## Example
/// ## Examples
///
/// ```
/// use rootcause::hooks::{Hooks, builtin_hooks::location::LocationHook};
Expand Down
2 changes: 1 addition & 1 deletion src/report/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{ReportRef, markers::Dynamic};
/// An iterator over a report and all its descendant reports in depth-first
/// order.
///
/// This iterator yields `ReportRef` items, which are references to the reports
/// This iterator yields [`ReportRef`] items, which are references to the reports
/// in the hierarchy. The iterator traverses the report tree in a depth-first
/// manner, starting from the root report and visiting each child report before
/// moving to the next sibling.
Expand Down
2 changes: 1 addition & 1 deletion src/report/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ impl<C: ?Sized, O, T> Report<C, O, T> {
/// ```
/// # use rootcause::{prelude::*, markers::SendSync};
/// # use core::any::TypeId;
/// let report = Report::new_sendsync_custom::<handlers::Debug>("error message");
/// let report : Report<&'static str> = Report::new_custom::<handlers::Debug>("error message");
/// let handler_type = report.current_context_handler_type_id();
/// assert_eq!(handler_type, TypeId::of::<handlers::Debug>());
/// ```
Expand Down
2 changes: 2 additions & 0 deletions src/report_attachment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//! - [`ReportAttachment`]: An owned attachment that can be added to a report
//! - [`ReportAttachmentRef`]: A reference to an attachment, typically obtained
//! from a report
//! - [`ReportAttachmentMut`]: A mutable to an attachment, typically obtained
//! from a report during construction of the report
//!
//! # Creating Attachments
//!
Expand Down
131 changes: 131 additions & 0 deletions src/report_attachment/mut_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
///
/// To get back the attachment with a concrete `A` you can use the method
/// [`ReportAttachmentMut::downcast_attachment`].
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*, report_attachment::ReportAttachment, markers::*};
/// let mut known_type = ReportAttachment::new_sendsync(42i32);
/// let the_answer = known_type.format_inner().to_string();
/// let mutable = known_type.as_mut();
/// let unknown_type = mutable.into_dynamic();
/// assert_eq!(unknown_type.format_inner().to_string(), the_answer);
/// ```
#[must_use]
pub fn into_dynamic(self) -> ReportAttachmentMut<'a, Dynamic> {
let raw = self.into_raw_mut();
Expand All @@ -224,6 +235,17 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
}

/// Returns an immutable reference to the attachment.
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*, report_attachment::ReportAttachment, markers::*};
/// let mut attachment = ReportAttachment::new_sendsync(42i32);
/// let the_answer = attachment.format_inner().to_string();
/// let mutable = attachment.as_mut();
/// let reference = mutable.as_ref();
/// assert_eq!(reference.format_inner().to_string(), the_answer);
/// ```
#[must_use]
pub fn as_ref(&self) -> ReportAttachmentRef<'_, A> {
let raw = self.as_raw_ref();
Expand All @@ -241,6 +263,16 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {

/// Consumes the [`ReportAttachmentMut`] and returns a
/// [`ReportAttachmentRef`] with same lifetime.
///
/// # Examples
/// ```
/// # use rootcause::{prelude::*, report_attachment::ReportAttachment, markers::*};
/// let mut attachment = ReportAttachment::new_sendsync(42i32);
/// let the_answer = attachment.format_inner().to_string();
/// let mutable = attachment.as_mut();
/// let reference = mutable.into_ref();
/// assert_eq!(reference.format_inner().to_string(), the_answer);
/// ```
#[must_use]
pub fn into_ref(self) -> ReportAttachmentRef<'a, A> {
let raw = self.into_raw_mut();
Expand All @@ -255,6 +287,22 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {

/// Reborrows the [`ReportAttachmentMut`] to return a new
/// [`ReportAttachmentMut`] with a shorter lifetime.
///
/// # Examples
///
/// ```
/// # use rootcause::{*, report_attachment::*, handlers::*};
/// let mut atch = ReportAttachment::new_sendsync_custom::<Display>(40i32);
/// {
/// let mut atch_mut_1 = atch.as_mut();
/// {
/// let mut atch_mut_2 = atch_mut_1.as_mut();
/// *atch_mut_2.inner_mut() += 1;
/// }
/// *atch_mut_1.inner_mut() += 1;
/// }
/// assert_eq!(atch.inner(), &42i32);
/// ```
#[must_use]
pub fn as_mut(&mut self) -> ReportAttachmentMut<'_, A> {
let raw = self.as_raw_mut();
Expand Down Expand Up @@ -323,6 +371,16 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
///
/// [`handlers::Display`]: crate::handlers::Display
/// [`handlers::Debug`]: crate::handlers::Debug
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*, report_attachment::ReportAttachment, handlers::*};
/// # use std::any::*;
/// let mut attachment = ReportAttachment::new_sendsync(42i32);
/// let mutable = attachment.as_mut();
/// assert_eq!(mutable.inner_handler_type_id(), TypeId::of::<Display>());
/// ```
#[must_use]
pub fn inner_handler_type_id(&self) -> TypeId {
self.as_raw_ref().attachment_handler_type_id()
Expand All @@ -342,6 +400,15 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
/// [`Display`]: core::fmt::Display
/// [`Debug`]: core::fmt::Debug
/// [`format_inner_unhooked`]: Self::format_inner_unhooked
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*, report_attachment::ReportAttachment, handlers::*};
/// let mut attachment = ReportAttachment::new_sendsync(42i32);
/// let mutable = attachment.as_mut();
/// assert_eq!(mutable.format_inner().to_string(), "42");
/// ```
#[must_use]
pub fn format_inner(&self) -> impl core::fmt::Display + core::fmt::Debug {
self.as_ref().format_inner()
Expand All @@ -361,6 +428,15 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
/// [`Display`]: core::fmt::Display
/// [`Debug`]: core::fmt::Debug
/// [`format_inner`]: Self::format_inner
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*, report_attachment::ReportAttachment, handlers::*};
/// let mut attachment = ReportAttachment::new_sendsync(42i32);
/// let mutable = attachment.as_mut();
/// assert_eq!(mutable.format_inner_unhooked().to_string(), "42");
/// ```
#[must_use]
pub fn format_inner_unhooked(&self) -> impl core::fmt::Display + core::fmt::Debug {
self.as_ref().format_inner_unhooked()
Expand All @@ -382,6 +458,20 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
///
/// [`Display`]: core::fmt::Display
/// [`Debug`]: core::fmt::Debug
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*,
/// # report_attachment::ReportAttachment,
/// # handlers::*, hooks::builtin_hooks::location::*};
///
/// let location = Location { file: "the-answer.rs", line: 42 };
/// let mut attachment = ReportAttachment::new_sendsync_custom::<LocationHandler>(location);
/// let mutable = attachment.as_ref();
/// let formatting = mutable.preferred_formatting_style(FormattingFunction::Display);
/// assert_eq!(formatting.priority, 20);
/// ```
#[must_use]
pub fn preferred_formatting_style(
&self,
Expand All @@ -408,6 +498,20 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
/// [`Display`]: core::fmt::Display
/// [`Debug`]: core::fmt::Debug
/// [`preferred_formatting_style`]: Self::preferred_formatting_style
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*,
/// # report_attachment::ReportAttachment,
/// # handlers::*, hooks::builtin_hooks::location::*};
///
/// let location = Location { file: "the-answer.rs", line: 42 };
/// let mut attachment = ReportAttachment::new_sendsync_custom::<LocationHandler>(location);
/// let mutable = attachment.as_ref();
/// let formatting = mutable.preferred_formatting_style_unhooked(FormattingFunction::Display);
/// assert_eq!(formatting.priority, 20);
/// ```
#[must_use]
pub fn preferred_formatting_style_unhooked(
&self,
Expand All @@ -425,6 +529,16 @@ impl<'a, A: ?Sized> ReportAttachmentMut<'a, A> {
/// See [`PreformattedAttachment`] for more information.
///
/// [`PreformattedAttachment`](crate::preformatted::PreformattedAttachment)
///
/// # Examples
///
/// ```
/// # use rootcause::{prelude::*, report_attachment::ReportAttachment};
/// let mut attachment = ReportAttachment::new_sendsync(42i32);
/// let mutable = attachment.as_mut();
/// let preformat = mutable.preformat();
/// assert_eq!(attachment.format_inner().to_string(), preformat.format_inner().to_string());
/// ```
#[track_caller]
#[must_use]
pub fn preformat(&self) -> ReportAttachment<PreformattedAttachment, SendSync> {
Expand Down Expand Up @@ -546,6 +660,23 @@ impl<'a> ReportAttachmentMut<'a, Dynamic> {
/// calling [`inner_type_id()`] first.
///
/// [`inner_type_id()`]: ReportAttachmentRef::inner_type_id
///
/// # Examples
/// ```
/// # use rootcause::{
/// # markers::Dynamic,
/// # prelude::*,
/// # report_attachment::{ReportAttachment, ReportAttachmentMut},
/// # };
///
/// let attachment: ReportAttachment<&str> = ReportAttachment::new("text data");
/// let mut attachment: ReportAttachment<Dynamic> = attachment.into_dynamic();
/// let mutable: ReportAttachmentMut<'_, Dynamic> = attachment.as_mut();
///
/// // SAFETY: We know the attachment contains &str data
/// let data: &&str = unsafe { mutable.downcast_inner_unchecked() };
/// assert_eq!(*data, "text data");
/// ```
#[must_use]
pub unsafe fn downcast_inner_unchecked<A>(&self) -> &A
where
Expand Down
Loading
Loading