coremem_types: enums don't require their variant to be Copy

this is safe because the variant is necessarily not ZST.
if it was ZST it could just be stored explicitly instead of folding it
into the first element, and that case should still be OK.
This commit is contained in:
2022-07-21 18:31:31 -07:00
parent 9153dfbb7a
commit 960804598a
2 changed files with 15 additions and 2 deletions

View File

@@ -110,11 +110,11 @@ where
impl<L> EnumRequirements for Enum<(), L>
where
L: list::Meta + Indexable<P0>,
list::ElementAt<P0, L>: Copy + DiscriminantCodable<<<L as list::Meta>::Length as PeanoNonZero>::Prev>,
list::ElementAt<P0, L>: DiscriminantCodable<<<L as list::Meta>::Length as PeanoNonZero>::Prev>,
{
type MaxDiscr = <<L as list::Meta>::Length as PeanoNonZero>::Prev;
fn discr(&self) -> Discr<Self::MaxDiscr> {
self.1.get().discr()
self.1.get_ref().discr()
}
}

View File

@@ -32,6 +32,7 @@ impl<H, T> Node<H, T> {
pub trait Indexable<P: Peano> {
type Element;
fn get(&self) -> Self::Element where Self::Element: Copy;
fn get_ref(&self) -> &Self::Element;
}
impl<E0, T> Indexable<P0> for Node<E0, T> {
@@ -39,6 +40,9 @@ impl<E0, T> Indexable<P0> for Node<E0, T> {
fn get(&self) -> Self::Element where Self::Element: Copy {
self.head
}
fn get_ref(&self) -> &Self::Element {
&self.head
}
}
impl<E0, E1, T> Indexable<P1> for Node<E0, Node<E1, T>> {
@@ -46,6 +50,9 @@ impl<E0, E1, T> Indexable<P1> for Node<E0, Node<E1, T>> {
fn get(&self) -> Self::Element where Self::Element: Copy {
self.tail.head
}
fn get_ref(&self) -> &Self::Element {
&self.tail.head
}
}
impl<E0, E1, E2, T> Indexable<P2> for Node<E0, Node<E1, Node<E2, T>>> {
@@ -53,6 +60,9 @@ impl<E0, E1, E2, T> Indexable<P2> for Node<E0, Node<E1, Node<E2, T>>> {
fn get(&self) -> Self::Element where Self::Element: Copy {
self.tail.tail.head
}
fn get_ref(&self) -> &Self::Element {
&self.tail.tail.head
}
}
impl<E0, E1, E2, E3, T> Indexable<P3> for Node<E0, Node<E1, Node<E2, Node<E3, T>>>> {
@@ -60,6 +70,9 @@ impl<E0, E1, E2, E3, T> Indexable<P3> for Node<E0, Node<E1, Node<E2, Node<E3, T>
fn get(&self) -> Self::Element where Self::Element: Copy {
self.tail.tail.tail.head
}
fn get_ref(&self) -> &Self::Element {
&self.tail.tail.tail.head
}
}
pub trait IntoList {