pub mod prelude
{
pub use super::traits::*;
}
pub mod traits
{
pub use super::{SharedCount, SharedDowngrade, SharedUpgrade};
}
pub trait SharedCount
{
fn strong_count(&self) -> usize;
fn weak_count(&self) -> usize;
}
pub trait SharedUpgrade: SharedCount
{
type Output: SharedCount + SharedDowngrade; fn upgrade(&self) -> Option<Self::Output>;
}
pub trait SharedDowngrade: SharedCount
{
type Ouput: SharedCount + SharedUpgrade; fn downgrade(&self) -> Self::Ouput;
}
#[cfg(feature = "std")]
mod std_impl
{
use super::{SharedCount, SharedDowngrade, SharedUpgrade};
impl<T: ?Sized> SharedCount for std::boxed::Box<T>
{
fn strong_count(&self) -> usize { 1 }
fn weak_count(&self) -> usize { 0 }
}
impl<T: ?Sized> SharedCount for std::rc::Weak<T>
{
fn strong_count(&self) -> usize { Self::strong_count(self) }
fn weak_count(&self) -> usize { Self::weak_count(self) }
}
impl<T: ?Sized> SharedCount for std::rc::Rc<T>
{
fn strong_count(&self) -> usize { Self::strong_count(self) }
fn weak_count(&self) -> usize { Self::weak_count(self) }
}
impl<T: ?Sized> SharedCount for std::sync::Weak<T>
{
fn strong_count(&self) -> usize { Self::weak_count(self) }
fn weak_count(&self) -> usize { Self::weak_count(self) }
}
impl<T: ?Sized> SharedCount for std::sync::Arc<T>
{
fn strong_count(&self) -> usize { Self::weak_count(self) }
fn weak_count(&self) -> usize { Self::weak_count(self) }
}
impl<T: ?Sized> SharedUpgrade for std::rc::Weak<T>
{
type Output = std::rc::Rc<T>;
fn upgrade(&self) -> Option<Self::Output> { Self::upgrade(self) }
}
impl<T: ?Sized> SharedDowngrade for std::rc::Rc<T>
{
type Ouput = std::rc::Weak<T>;
fn downgrade(&self) -> Self::Ouput { Self::downgrade(self) }
}
impl<T: ?Sized> SharedUpgrade for std::sync::Weak<T>
{
type Output = std::sync::Arc<T>;
fn upgrade(&self) -> Option<Self::Output> { Self::upgrade(self) }
}
impl<T: ?Sized> SharedDowngrade for std::sync::Arc<T>
{
type Ouput = std::sync::Weak<T>;
fn downgrade(&self) -> Self::Ouput { Self::downgrade(self) }
}
}