pub struct Cloneable;Expand description
Marker type for cloneable reports and report references.
This marker is used with both Report<C, Cloneable, T> and
ReportRef<C, Cloneable>. It indicates shared ownership
using reference counting (Arc internally), which allows cheap cloning but
prevents mutation.
§Usage with Report
For Report<C, Cloneable, T>, this marker means the report
itself implements Clone, allowing you to cheaply clone the entire report
(shallow copy via Arc).
§Usage with ReportRef
For ReportRef<C, Cloneable>, the marker enables the
clone_arc method, which clones the
underlying Arc to produce an owned Report<C, Cloneable, T>. Note that ReportRef itself is always Copy and
Clone regardless of the ownership marker - the Cloneable
marker specifically enables converting the reference back to an owned
report.
§When to Use
Use Cloneable reports when you need to:
- Share an error report across multiple code paths
- Store reports in collections that require
Clone - Return the same error from multiple places without deep copying
§Converting to Cloneable
Convert a Mutable report to Cloneable using
into_cloneable:
use rootcause::prelude::*;
let report: Report<String, markers::Mutable> = report!("Error".to_string());
// Convert to cloneable
let cloneable: Report<String, markers::Cloneable> = report.into_cloneable();
// Now can clone cheaply (shallow clone via Arc)
let clone1: Report<String, markers::Cloneable> = cloneable.clone();
let clone2: Report<String, markers::Cloneable> = cloneable.clone();§Examples
Cloning owned reports:
use rootcause::prelude::*;
fn process_error(error: Report<String, markers::Cloneable>) {
// Can clone the error to pass to multiple handlers
let for_logging = error.clone();
let for_metrics = error.clone();
println!("Logging: {}", for_logging);
println!("Metrics: {}", for_metrics);
}
let report: Report<String> = report!("An error occurred".to_string());
process_error(report.into_cloneable());Using clone_arc on report references:
use rootcause::{ReportRef, prelude::*};
let report: Report<String, markers::Cloneable> = report!("Error".to_string()).into_cloneable();
// Get a reference (ReportRef is Copy, so this is cheap)
let report_ref: ReportRef<String, markers::Cloneable> = report.as_ref();
// Clone the underlying Arc to get an owned Report
let owned: Report<String, markers::Cloneable> = report_ref.clone_arc();Trait Implementations§
Source§impl Ord for Cloneable
impl Ord for Cloneable
Source§impl PartialOrd for Cloneable
impl PartialOrd for Cloneable
Source§impl ReportOwnershipMarker for Cloneable
impl ReportOwnershipMarker for Cloneable
impl Copy for Cloneable
impl Eq for Cloneable
impl StructuralPartialEq for Cloneable
Auto Trait Implementations§
impl Freeze for Cloneable
impl RefUnwindSafe for Cloneable
impl Send for Cloneable
impl Sync for Cloneable
impl Unpin for Cloneable
impl UnwindSafe for Cloneable
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.