Skip to main content

ReportOwnershipMarker

Trait ReportOwnershipMarker 

Source
pub trait ReportOwnershipMarker: Sealed {
    type RefMarker;
}
Expand description

Marker trait for ownership semantics of owned reports.

This trait is implemented for Mutable and Cloneable, the two ownership markers that can be used with Report<C, O, T>. It exists primarily to enable the associated type RefMarker, which determines the ownership marker used when creating a reference to the report.

§Relationship to Report Construction

While this trait defines the ownership modes, the actual enforcement of ownership invariants happens at report construction time. It is impossible to construct a Report<_, Mutable> that doesn’t have unique ownership, or a Report<_, Cloneable> that hasn’t been properly set up for shared ownership.

§Ownership Modes

  • Mutable: Indicates unique ownership. The report can be mutated but not cloned. Methods like attach and as_mut are only available in this mode.

  • Cloneable: Indicates shared ownership via reference counting. The report can be cloned cheaply but cannot be mutated since there may be multiple references.

§Associated Types

The RefMarker associated type determines what kind of reference you get when calling as_ref:

§Implementation

This trait is sealed and cannot be implemented outside of this crate. You should use the provided implementations for Mutable and Cloneable.

§Examples

ReportOwnershipMarker is typically used as a bound to write functions that accept both Mutable and Cloneable reports:

use rootcause::{
    markers::{Cloneable, Mutable, ReportOwnershipMarker},
    prelude::*,
};

fn describe<O: ReportOwnershipMarker>(report: Report<&'static str, O>) -> String {
    report.current_context().to_string()
}

let context: &'static str = "oops";
let mutable: Report<&str, Mutable> = report!(context);
assert_eq!(describe(mutable), "oops");

let cloneable: Report<&str, Cloneable> = report!(context).into_cloneable();
assert_eq!(describe(cloneable), "oops");

Required Associated Types§

Source

type RefMarker

The ownership marker for references to this report type.

This determines what type of reference is created when you call Report::as_ref:

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§