ReportCollection

Struct ReportCollection 

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

A collection of reports.

You can think of a ReportCollection<C, T> as a wrapper around a Vec<Report<C, markers::Cloneable, T>>, however, it has a slightly different API:

  • It provides methods such as context and context_custom to create new reports with the collection as children.
  • It has convenience methods to convert between different context and thread safety markers such as into_dynamic and into_local.
  • It is also possible to convert between different context and thread safety markers using the From and Into traits.

Implementations§

Source§

impl<C: ?Sized, T> ReportCollection<C, T>

Source

pub fn new() -> Self

Creates a new, empty ReportCollection.

The collection will be initially empty and will have no capacity allocated. This method is equivalent to calling Default::default().

§Examples
use rootcause::report_collection::ReportCollection;

let collection: ReportCollection = ReportCollection::new();
assert!(collection.is_empty());
assert_eq!(collection.len(), 0);
Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new, empty ReportCollection with the specified capacity.

The collection will be able to hold at least capacity reports without reallocating. If you plan to add a known number of reports to the collection, using this method can help improve performance by reducing the number of memory allocations needed.

§Examples
use rootcause::report_collection::ReportCollection;

let collection: ReportCollection = ReportCollection::with_capacity(10);
assert!(collection.is_empty());
assert_eq!(collection.len(), 0);
assert!(collection.capacity() >= 10);
Source

pub fn push(&mut self, report: Report<C, Cloneable, T>)

Appends a report to the end of the collection.

This method takes ownership of the report and adds it to the collection. The report must have the Cloneable ownership marker, which allows it to be stored in the collection and cloned when needed.

§Examples
use rootcause::{report, report_collection::ReportCollection};

let mut collection = ReportCollection::new();
let report = report!("An error occurred").into_cloneable();

collection.push(report);
assert_eq!(collection.len(), 1);
Source

pub fn pop(&mut self) -> Option<Report<C, Cloneable, T>>

Removes and returns the last report from the collection.

Returns None if the collection is empty.

This method provides LIFO (last in, first out) behavior, making the collection behave like a stack for the most recently added reports.

§Examples
use rootcause::{report, report_collection::ReportCollection};

let mut collection = ReportCollection::new();
let report1 = report!("First error").into_cloneable();
let report2 = report!("Second error").into_cloneable();

collection.push(report1);
collection.push(report2);

let last_report = collection.pop().unwrap();
assert_eq!(collection.len(), 1);

let empty_pop = ReportCollection::<&str>::new().pop();
assert!(empty_pop.is_none());
Source

pub fn len(&self) -> usize

Returns the number of reports in the collection.

§Examples
use rootcause::{report, report_collection::ReportCollection};

let mut collection = ReportCollection::new();
assert_eq!(collection.len(), 0);

collection.push(report!("Error 1").into_cloneable());
collection.push(report!("Error 2").into_cloneable());
assert_eq!(collection.len(), 2);
Source

pub fn capacity(&self) -> usize

Returns the capacity of the collection.

The capacity is the number of reports the collection can hold without allocating additional memory.

§Examples
use rootcause::{
    markers::{Dynamic, SendSync},
    report,
    report_collection::ReportCollection,
};

let collection = ReportCollection::<Dynamic, SendSync>::with_capacity(5);
assert!(collection.capacity() <= 5);
Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more reports to be inserted in the collection.

The collection may reserve more space to avoid frequent reallocations.

§Examples
use rootcause::{
    markers::{Dynamic, SendSync},
    report,
    report_collection::ReportCollection,
};

let mut collection = ReportCollection::<Dynamic, SendSync>::new();
collection.reserve(10);
assert!(collection.capacity() >= 10);
Source

pub fn get(&self, index: usize) -> Option<ReportRef<'_, C, Cloneable, T>>

Returns a reference to the report at the given index.

Returns None if the index is out of bounds.

§Examples
use rootcause::{report, report_collection::ReportCollection};

let mut collection = ReportCollection::new();
collection.push(report!("First error").into_cloneable());
collection.push(report!("Second error").into_cloneable());

let first_report = collection.get(0).unwrap();
let second_report = collection.get(1).unwrap();
let out_of_bounds = collection.get(2);

assert!(out_of_bounds.is_none());
Source

pub fn is_empty(&self) -> bool

Returns true if the collection contains no reports.

§Examples
use rootcause::{report, report_collection::ReportCollection};

let mut collection = ReportCollection::new();
assert!(collection.is_empty());

collection.push(report!("An error").into_cloneable());
assert!(!collection.is_empty());
Source

pub fn iter(&self) -> ReportCollectionIter<'_, C, T>

Returns an iterator over references to the reports in the collection.

The iterator yields ReportRef items, which are lightweight references to the reports in the collection.

§Examples
use rootcause::{report, report_collection::ReportCollection};

let mut collection = ReportCollection::new();
collection.push(report!("Error 1").into_cloneable());
collection.push(report!("Error 2").into_cloneable());

for (i, report_ref) in collection.iter().enumerate() {
    println!("Report {}: {}", i, report_ref);
}
Source

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

Formats the entire collection using a specific report formatting hook.

This method allows you to format a collection of reports 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, report,
    report_collection::ReportCollection,
};

let mut collection = ReportCollection::new();
collection.push(report!("Error 1").into_cloneable());
collection.push(report!("Error 2").into_cloneable());

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

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

Converts the collection to use type-erased contexts via Dynamic.

This performs type erasure on the context type parameter, allowing collections with different concrete context types to be stored together or passed to functions that accept ReportCollection<Dynamic, T>.

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

The thread safety marker T is preserved during this conversion.

§Examples
use rootcause::{markers::Dynamic, report, report_collection::ReportCollection};

let mut collection: ReportCollection<Dynamic> = ReportCollection::new();
collection.push(report!("String error").into_cloneable());

let erased: ReportCollection<Dynamic> = collection.into_dynamic();
assert_eq!(erased.len(), 1);
Source

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

Returns a reference to the collection with type-erased contexts via Dynamic.

Source

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

Converts the collection to use Local thread safety semantics.

This changes the thread safety marker from any type to Local, which means the resulting collection will not implement Send or Sync. This is useful when you want to use the collection in single-threaded contexts and potentially store non-thread-safe data.

This method does not actually modify the collection in any way. It only has the effect of “forgetting” that all objects in the ReportCollection are actually Send and Sync.

The context type C is preserved during this conversion.

§Examples
use rootcause::{
    markers::{Dynamic, Local},
    report,
    report_collection::ReportCollection,
};

let mut collection: ReportCollection<Dynamic> = ReportCollection::new(); // defaults to SendSync
collection.push(report!("An error").into_cloneable());

let local_collection: ReportCollection<Dynamic, Local> = collection.into_local();
assert_eq!(local_collection.len(), 1);
Source

pub fn as_local(&self) -> &ReportCollection<C, Local>

Returns a reference to the collection with Local thread safety semantics.

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 collection as the children 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 ReportCollection and returns a new Report.

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_collection: ReportCollection = [report!("error A"), report!("error B")]
    .into_iter()
    .collect();
let report: Report<&str> = report_collection.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 collection as the children of the new report.

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

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_collection: ReportCollection = [report!("error A"), report!("error B")]
    .into_iter()
    .collect();
let report: Report<&str> = report_collection.context_custom::<handlers::Debug, _>("context");
Source§

impl<C: ?Sized> ReportCollection<C, SendSync>

Source

pub fn new_sendsync() -> Self

Creates a new, empty ReportCollection with SendSync thread safety.

This is equivalent to calling new() but makes the thread safety marker explicit. The resulting collection can be safely sent between threads and shared across threads.

§Examples
use rootcause::{markers::SendSync, report_collection::ReportCollection};

let collection: ReportCollection<&str, SendSync> = ReportCollection::new_sendsync();
assert!(collection.is_empty());
Source§

impl<C: ?Sized> ReportCollection<C, Local>

Source

pub fn new_local() -> Self

Creates a new, empty ReportCollection with Local thread safety.

This creates a collection that is not Send or Sync, meaning it cannot be transferred between threads or shared across threads. This is useful for single-threaded applications or when you need to store non-thread-safe data.

§Examples
use rootcause::{markers::Local, report_collection::ReportCollection};

let collection: ReportCollection<&str, Local> = ReportCollection::new_local();
assert!(collection.is_empty());

Trait Implementations§

Source§

impl<C: ?Sized, T> Clone for ReportCollection<C, 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, T> Debug for ReportCollection<C, T>

Source§

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

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

impl<C: ?Sized> Default for ReportCollection<C, SendSync>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<C: ?Sized> Default for ReportCollection<C, Local>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<C: ?Sized, T> Display for ReportCollection<C, 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<'a, C: ?Sized, T> Extend<ReportRef<'a, C, Cloneable, T>> for ReportCollection<C, T>

Source§

fn extend<I: IntoIterator<Item = ReportRef<'a, C, Cloneable, 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<'a, C: Sized, T> Extend<ReportRef<'a, C, Cloneable, T>> for ReportCollection<Dynamic, T>

Source§

fn extend<I: IntoIterator<Item = ReportRef<'a, C, Cloneable, 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<const N: usize, C: ?Sized, T> From<[Report<C, Cloneable, T>; N]> for ReportCollection<C, T>

Source§

fn from(reports: [Report<C, Cloneable, T>; N]) -> Self

Converts to this type from the input type.
Source§

impl<C> From<ReportCollection<C>> for ReportCollection<Dynamic, SendSync>

Source§

fn from(report_collection: ReportCollection<C, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<ReportCollection<C>> for ReportCollection<C, Local>

Source§

fn from(report_collection: ReportCollection<C, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<ReportCollection<C>> for ReportCollection<Dynamic, Local>

Source§

fn from(report_collection: ReportCollection<C, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<ReportCollection<C, Local>> for ReportCollection<Dynamic, Local>

Source§

fn from(report_collection: ReportCollection<C, Local>) -> Self

Converts to this type from the input type.
Source§

impl From<ReportCollection> for ReportCollection<Dynamic, Local>

Source§

fn from(report_collection: ReportCollection<Dynamic, SendSync>) -> Self

Converts to this type from the input type.
Source§

impl<C: ?Sized, T> From<Vec<Report<C, Cloneable, T>>> for ReportCollection<C, T>

Source§

fn from(reports: Vec<Report<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<'a, C: ?Sized, T> FromIterator<ReportRef<'a, C, Cloneable, T>> for ReportCollection<C, T>

Source§

fn from_iter<I: IntoIterator<Item = ReportRef<'a, C, Cloneable, T>>>( iter: I, ) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, C: Sized, T> FromIterator<ReportRef<'a, C, Cloneable, T>> for ReportCollection<Dynamic, T>

Source§

fn from_iter<I: IntoIterator<Item = ReportRef<'a, C, Cloneable, T>>>( iter: I, ) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, C: ?Sized, T> IntoIterator for &'a ReportCollection<C, T>

Source§

type IntoIter = ReportCollectionIter<'a, C, T>

Which kind of iterator are we turning this into?
Source§

type Item = ReportRef<'a, C, Cloneable, T>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<C: ?Sized, T> IntoIterator for ReportCollection<C, T>

Source§

type IntoIter = ReportCollectionIntoIter<C, T>

Which kind of iterator are we turning this into?
Source§

type Item = Report<C, Cloneable, T>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<C, T> IntoReportCollection<Local> for ReportCollection<C, T>
where C: ?Sized,

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> IntoReportCollection<SendSync> for ReportCollection<C, SendSync>
where C: ?Sized,

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> Send for ReportCollection<C, SendSync>

Source§

impl<C: ?Sized> Sync for ReportCollection<C, SendSync>

Source§

impl<C: ?Sized, T> Unpin for ReportCollection<C, T>

Auto Trait Implementations§

§

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

§

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

§

impl<Context = Dynamic, ThreadSafety = SendSync> !Send for ReportCollection<Context, ThreadSafety>

§

impl<Context = Dynamic, ThreadSafety = SendSync> !Sync for ReportCollection<Context, ThreadSafety>

§

impl<Context, ThreadSafety> UnwindSafe for ReportCollection<Context, ThreadSafety>
where Context: UnwindSafe + ?Sized, 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<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,