Skip to main content

ObjectMarkerFor

Trait ObjectMarkerFor 

Source
pub trait ObjectMarkerFor<T>:
    Sealed
    + Sized
    + 'static { }
Expand description

Marker trait combining object and thread-safety requirements.

This trait enforces thread-safety constraints for context and attachment data at report construction time. Reports can only be constructed when their context and attachments satisfy the requirements of the thread-safety marker.

§Implementations

  • For T = Local: Implemented for all Sized + 'static types, regardless of their Send/Sync status. This allows using types like Rc in local reports.

  • For T = SendSync: Implemented only for Sized + 'static types that are also Send + Sync. This ensures thread-safe reports can only be constructed with thread-safe data.

§Enforcement at Construction

The key insight is that this trait is used as a bound during report construction. You cannot create a Report<C, _, SendSync> unless C: ObjectMarkerFor<SendSync>, which requires C: Send + Sync. This makes it impossible to accidentally create an invalid report:

use std::rc::Rc;
use rootcause::prelude::*;

// This won't compile because Rc is not Send + Sync
let rc_data: Rc<String> = Rc::new("error".to_string());
let report: Report<Rc<String>, markers::Mutable, markers::SendSync> = report!(rc_data);

Use Local instead for non-thread-safe data:

use std::rc::Rc;

use rootcause::prelude::*;

let rc_data: Rc<String> = Rc::new("error".to_string());
let report: Report<Rc<String>, markers::Mutable, markers::Local> = report!(rc_data);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Source§

impl<O: Sized + 'static> ObjectMarkerFor<Local> for O