Closed
Description
Once we publish 0.9, which will have a sufficiently high MSRV that we have access to GAT, we implement the following design. This will permit all concrete Invariants
types to be private. This, in turn, means that we can preserve the ability to make future changes to how we represent invariants, or even add new invariants.
trait Invariants {
// The invariants encoded by `Self`
type Aliasing: Aliasing;
type Alignment: Alignment;
type Validity: Validity;
// `Self` except with one invariant modified
type WithAliasing<A: Aliasing>: Invariants<
Aliasing = A,
Alignment = Self::Alignment,
Validity = Self::Validity,
>;
type WithAlignment<A: Alignment>: Invariants<
Aliasing = Self::Aliasing,
Alignment = A,
Validity = Self::Validity,
>;
type WithValidity<A: Validity>: Invariants<
Aliasing = Self::Aliasing,
Alignment = Self::Alignment,
Validity = V,
>;
}
struct Ptr<'a, T, I: Invariants> { ... }
impl<'a, T, I: Invariants> Ptr<'a, T, I> {
// Look! No concrete types!
pub unsafe fn assume_aligned(self) -> Ptr<'a, T, I::WithAlignment<Aligned>> { ... }
}
Metadata
Metadata
Assignees
Labels
No labels