use crate::container_traits::{
Container, FragileContainer, FragileMutContainer, MutContainer, TryMutContainer,
};
pub trait TLike {
type Container<T>: MutContainer<T>;
}
pub trait FragileTLike {
type Container<T>: FragileMutContainer<T>;
}
pub trait BoxLike {
type Container<T: ?Sized>: MutContainer<T>;
}
pub trait FragileBoxLike {
type Container<T: ?Sized>: FragileMutContainer<T>;
}
pub trait RcLike {
type Container<T: ?Sized>: Container<T> + Clone;
}
pub trait FragileRcLike {
type Container<T: ?Sized>: FragileContainer<T> + Clone;
}
pub trait RcRefCellLike {
type Container<T: ?Sized>: FragileMutContainer<T> + Clone;
}
pub trait ArcLike {
type Container<T: ?Sized + Send + Sync>: Container<T> + Clone + Send + Sync;
}
pub trait FragileArcLike {
type Container<T: ?Sized + Send + Sync>: FragileContainer<T> + Clone + Send + Sync;
}
pub trait ArcRwLockLike {
type Container<T: ?Sized + Send + Sync>: FragileMutContainer<T> + Clone + Send + Sync;
}
pub trait ArcMutexLike {
type Container<T: ?Sized + Send>: FragileMutContainer<T> + Clone + Send + Sync;
}
#[cfg_attr(
feature = "alloc",
doc = "[`CheckedRcRefCell<T>`]: crate::CheckedRcRefCell",
)]
#[cfg_attr(
not(feature = "alloc"),
doc = "[`CheckedRcRefCell<T>`]: \
https://docs.rs/generic-container/0/generic_container/struct.CheckedRcRefCell.html",
)]
pub trait CheckedRcRefCellLike {
#[cfg_attr(
feature = "alloc",
doc = "[`CheckedRcRefCell<T>`]: crate::CheckedRcRefCell",
)]
#[cfg_attr(
not(feature = "alloc"),
doc = "[`CheckedRcRefCell<T>`]: \
https://docs.rs/generic-container/0/generic_container/struct.CheckedRcRefCell.html",
)]
type Container<T: ?Sized>: TryMutContainer<T> + Clone;
}
#[cfg_attr(
feature = "thread-checked-lock",
doc = "[ThreadCheckedMutex]: thread_checked_lock::ThreadCheckedMutex",
)]
#[cfg_attr(
not(feature = "thread-checked-lock"),
doc = "[ThreadCheckedMutex]: \
https://docs.rs/thread-checked-lock/0/thread_checked_lock/struct.ThreadCheckedMutex.html",
)]
pub trait ArcThreadCheckedMutexLike {
#[cfg_attr(
feature = "thread-checked-lock",
doc = "[ThreadCheckedMutex]: thread_checked_lock::ThreadCheckedMutex",
)]
#[cfg_attr(
not(feature = "thread-checked-lock"),
doc = "[ThreadCheckedMutex]: \
https://docs.rs/thread-checked-lock/0/thread_checked_lock/struct.ThreadCheckedMutex.html",
)]
type Container<T: ?Sized + Send>: TryMutContainer<T> + Clone + Send + Sync;
}
#[cfg_attr(docsrs, doc(cfg(feature = "kinds")))]
#[derive(Default, Debug, Clone, Copy)]
pub struct TKind;
impl TLike for TKind {
type Container<T> = T;
}
impl FragileTLike for TKind {
type Container<T> = T;
}
#[cfg(any(feature = "alloc", doc))]
mod alloc_kinds {
use core::cell::RefCell;
use alloc::{boxed::Box, rc::Rc, sync::Arc};
use crate::impls::CheckedRcRefCell;
use super::{
ArcLike, BoxLike, CheckedRcRefCellLike,
FragileArcLike, FragileBoxLike, FragileTLike, FragileRcLike,
RcLike, RcRefCellLike, TLike,
};
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct BoxKind;
impl BoxLike for BoxKind {
type Container<T: ?Sized> = Box<T>;
}
impl FragileBoxLike for BoxKind {
type Container<T: ?Sized> = Box<T>;
}
impl TLike for BoxKind {
type Container<T> = Box<T>;
}
impl FragileTLike for BoxKind {
type Container<T> = Box<T>;
}
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct RcKind;
impl RcLike for RcKind {
type Container<T: ?Sized> = Rc<T>;
}
impl FragileRcLike for RcKind {
type Container<T: ?Sized> = Rc<T>;
}
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct ArcKind;
impl ArcLike for ArcKind {
type Container<T: ?Sized + Send + Sync> = Arc<T>;
}
impl FragileArcLike for ArcKind {
type Container<T: ?Sized + Send + Sync> = Arc<T>;
}
impl RcLike for ArcKind {
type Container<T: ?Sized> = Arc<T>;
}
impl FragileRcLike for ArcKind {
type Container<T: ?Sized> = Arc<T>;
}
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct RcRefCellKind;
impl RcRefCellLike for RcRefCellKind {
type Container<T: ?Sized> = Rc<RefCell<T>>;
}
impl FragileRcLike for RcRefCellKind {
type Container<T: ?Sized> = Rc<RefCell<T>>;
}
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct CheckedRcRefCellKind;
impl CheckedRcRefCellLike for CheckedRcRefCellKind {
type Container<T: ?Sized> = CheckedRcRefCell<T>;
}
}
#[cfg(any(feature = "alloc", doc))]
pub use self::alloc_kinds::{ArcKind, BoxKind, CheckedRcRefCellKind, RcKind, RcRefCellKind};
#[cfg(any(feature = "std", doc))]
mod std_kinds {
use alloc::sync::Arc;
use std::sync::{Mutex, RwLock};
use super::{ArcMutexLike, ArcRwLockLike, FragileArcLike, FragileRcLike, RcRefCellLike};
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct ArcRwLockKind;
impl ArcRwLockLike for ArcRwLockKind {
type Container<T: ?Sized + Send + Sync> = Arc<RwLock<T>>;
}
impl FragileArcLike for ArcRwLockKind {
type Container<T: ?Sized + Send + Sync> = Arc<RwLock<T>>;
}
impl RcRefCellLike for ArcRwLockKind {
type Container<T: ?Sized> = Arc<RwLock<T>>;
}
impl FragileRcLike for ArcRwLockKind {
type Container<T: ?Sized> = Arc<RwLock<T>>;
}
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct ArcMutexKind;
impl ArcMutexLike for ArcMutexKind {
type Container<T: ?Sized + Send> = Arc<Mutex<T>>;
}
impl ArcRwLockLike for ArcMutexKind {
type Container<T: ?Sized + Send + Sync> = Arc<Mutex<T>>;
}
impl FragileArcLike for ArcMutexKind {
type Container<T: ?Sized + Send + Sync> = Arc<Mutex<T>>;
}
impl RcRefCellLike for ArcMutexKind {
type Container<T: ?Sized> = Arc<Mutex<T>>;
}
impl FragileRcLike for ArcMutexKind {
type Container<T: ?Sized> = Arc<Mutex<T>>;
}
}
#[cfg(any(feature = "std", doc))]
pub use self::std_kinds::{ArcMutexKind, ArcRwLockKind};
#[cfg(feature = "thread-checked-lock")]
mod thread_checked_lock_kinds {
use alloc::sync::Arc;
use thread_checked_lock::ThreadCheckedMutex;
use super::{ArcThreadCheckedMutexLike, CheckedRcRefCellLike};
#[cfg_attr(docsrs, doc(cfg(all(feature = "thread-checked-lock", feature = "kinds"))))]
#[derive(Default, Debug, Clone, Copy)]
pub struct ArcThreadCheckedMutexKind;
impl ArcThreadCheckedMutexLike for ArcThreadCheckedMutexKind {
type Container<T: ?Sized + Send> = Arc<ThreadCheckedMutex<T>>;
}
impl CheckedRcRefCellLike for ArcThreadCheckedMutexKind {
type Container<T: ?Sized> = Arc<ThreadCheckedMutex<T>>;
}
}
#[cfg(feature = "thread-checked-lock")]
pub use self::thread_checked_lock_kinds::ArcThreadCheckedMutexKind;