flexrc/algorithm/
mod.rs

1mod hybrid;
2#[cfg(feature = "track_threads")]
3mod hybrid_threads;
4mod regular;
5
6use crate::FlexRcInner;
7
8pub use hybrid::*;
9pub use regular::*;
10
11pub trait Algorithm<META, META2> {
12    /// Create and return new metadata    
13    fn create() -> Self;
14
15    /// Returns true if this instance is the last one before final release of resources
16    fn is_unique(&self) -> bool;
17
18    /// Increment reference counters
19    fn clone(&self);
20
21    /// Decrement reference counters and return true if storage should be deallocated
22    fn drop(&self) -> bool;
23
24    /// Attempts to converts one inner type into another while consuming the other
25    fn try_into_other<T: ?Sized>(
26        &self,
27        inner: *mut FlexRcInner<META, META2, T>,
28    ) -> Result<*mut FlexRcInner<META2, META, T>, *mut FlexRcInner<META, META2, T>>;
29
30    /// Attempts to converts one inner type into another but NOT consuming the other
31    fn try_to_other<T: ?Sized>(
32        &self,
33        inner: *mut FlexRcInner<META, META2, T>,
34    ) -> Result<*mut FlexRcInner<META2, META, T>, *mut FlexRcInner<META, META2, T>>;
35}
36
37#[cfg(feature = "std")]
38#[inline]
39fn abort() {
40    std::process::abort()
41}
42
43#[cfg(not(feature = "std"))]
44#[inline]
45fn abort() {
46    // Abort not available on no_std
47    panic!("Reference count overflow");
48}