Trait IsContainer
pub trait IsContainer {
type Container<T>;
type Pointer<T>;
// Required method
fn get_pointer<T>(container: &Self::Container<T>) -> Self::Pointer<T>;
}
Expand description
An abstraction over the container type of a hybrid value of T
.
For example, the container type could be Hybrid<T>
, WeakHybrid<T>
,
Gpu<T>
or WeakGpu<T>
.
This is a way around Rust not having higher-kinded data types. It is used to make the container type generic while fixing the element type.
Example usage:
use craballoc::prelude::*;
#[derive(Clone, Debug)]
pub enum SomeDetails<Ct: IsContainer = HybridContainer> {
A(Ct::Container<usize>),
B(Ct::Container<u32>),
}
impl<Ct: IsContainer> SomeDetails<Ct> {
pub fn as_a(&self) -> Option<&Ct::Container<usize>> {
if let SomeDetails::A(v) = self {
Some(v)
} else {
None
}
}
}
Required Associated Types§
Required Methods§
fn get_pointer<T>(container: &Self::Container<T>) -> Self::Pointer<T>
fn get_pointer<T>(container: &Self::Container<T>) -> Self::Pointer<T>
Returns a pointer to the data within this container.
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.