reference_counted/lib.rs
1#![no_std]
2#![allow(unused_unsafe)]
3// #![cfg_attr(feature = "unstable", coerce_unsized, dispatch_from_dyn)]
4extern crate maybe_std as base;
5
6use smart_pointer::IntoMut;
7
8/// A smart pointer that keeps track of how many pointers refer to the same allocation and
9/// exposes this information in its API.
10pub trait ReferenceCounted<T: ?Sized>: IntoMut<T> + Clone {
11 /// Get the number of owning pointers referring to the same allocation.
12 ///
13 /// Implementations must fulfill that `ReferenceCounted::reference_count(this) == 1` implies
14 /// `IntoMut::con_make_mut(this) == true`.
15 fn reference_count(this: &Self) -> usize;
16}
17
18#[cfg(feature = "arc")]
19mod arc;
20#[cfg(feature = "arc")]
21pub use arc::*;
22
23#[cfg(feature = "arc")]
24mod rc;
25#[cfg(feature = "arc")]
26pub use rc::*;