pub enum Sum<L, R> {
Left(L),
Right(R),
}Expand description
The Sum Type, corresponding to the Either type in Rust.
Variants§
Implementations§
Source§impl<L, R> Sum<L, R>
impl<L, R> Sum<L, R>
pub fn arrow_Left_0(self) -> L
pub fn arrow_Right_0(self) -> R
Source§impl<L, R> Sum<L, R>
impl<L, R> Sum<L, R>
Sourcepub proof fn tracked_take_left(tracked self) -> tracked res : L
pub proof fn tracked_take_left(tracked self) -> tracked res : L
requires
self is Left,returnsself->Left_0,Sourcepub proof fn tracked_take_right(tracked self) -> tracked res : R
pub proof fn tracked_take_right(tracked self) -> tracked res : R
requires
self is Right,returnsself->Right_0,Sourcepub proof fn tracked_borrow_left(tracked &self) -> tracked res : &L
pub proof fn tracked_borrow_left(tracked &self) -> tracked res : &L
requires
self is Left,ensures*res == self->Left_0,Sourcepub proof fn tracked_borrow_right(tracked &self) -> tracked res : &R
pub proof fn tracked_borrow_right(tracked &self) -> tracked res : &R
requires
self is Right,ensures*res == self->Right_0,Sourcepub open spec fn lift_map_left<K>(m: Map<K, L>) -> Map<K, Self>
pub open spec fn lift_map_left<K>(m: Map<K, L>) -> Map<K, Self>
{ m.map_values(|w| Sum::<L, R>::Left(w)) }Sourcepub open spec fn lift_map_right<K>(m: Map<K, R>) -> Map<K, Self>
pub open spec fn lift_map_right<K>(m: Map<K, R>) -> Map<K, Self>
{ m.map_values(|v| Sum::<L, R>::Right(v)) }Sourcepub proof fn tracked_swap_left(tracked &mut self, tracked new_left: L) -> tracked res : L
pub proof fn tracked_swap_left(tracked &mut self, tracked new_left: L) -> tracked res : L
requires
*old(self) is Left,ensuresres == old(self)->Left_0,*self is Left,self->Left_0 == new_left,Sourcepub proof fn tracked_swap_right(tracked &mut self, tracked new_right: R) -> tracked res : R
pub proof fn tracked_swap_right(tracked &mut self, tracked new_right: R) -> tracked res : R
requires
*old(self) is Right,ensuresres == old(self)->Right_0,*self is Right,self->Right_0 == new_right,Trait Implementations§
Source§impl<A, B, const TOTAL: u64> Protocol<(), Sum<A, B>> for CsumP<A, B, TOTAL>
impl<A, B, const TOTAL: u64> Protocol<(), Sum<A, B>> for CsumP<A, B, TOTAL>
Source§open spec fn op(self, other: Self) -> Self
open spec fn op(self, other: Self) -> Self
{
match (self, other) {
(CsumP::Unit, x) => x,
(x, CsumP::Unit) => x,
(CsumP::Cinl(ov1, n1, b1), CsumP::Cinl(ov2, n2, b2)) => {
if !self.is_valid() || !other.is_valid() || n1 + n2 > TOTAL || b1 && b2
|| ov1 is Some && ov2 is Some
{
CsumP::CsumInvalid
} else {
CsumP::Cinl(if ov1 is Some { ov1 } else { ov2 }, n1 + n2, b1 || b2)
}
}
(CsumP::Cinr(ov1, n1, b1), CsumP::Cinr(ov2, n2, b2)) => {
if !self.is_valid() || !other.is_valid() || n1 + n2 > TOTAL || b1 && b2
|| ov1 is Some && ov2 is Some
{
CsumP::CsumInvalid
} else {
CsumP::Cinr(if ov1 is Some { ov1 } else { ov2 }, n1 + n2, b1 || b2)
}
}
_ => CsumP::CsumInvalid,
}
}Source§open spec fn rel(self, s: Map<(), Sum<A, B>>) -> bool
open spec fn rel(self, s: Map<(), Sum<A, B>>) -> bool
{
match self {
CsumP::Unit => s.is_empty(),
CsumP::Cinl(None, n, true) => 0 <= n <= TOTAL && s.is_empty(),
CsumP::Cinl(Some(a), n, true) => {
0 <= n <= TOTAL && s.contains_key(()) && s[()] == Sum::<A, B>::Left(a)
}
CsumP::Cinr(None, n, true) => 0 <= n <= TOTAL && s.is_empty(),
CsumP::Cinr(Some(b), n, true) => {
0 <= n <= TOTAL && s.contains_key(()) && s[()] == Sum::<A, B>::Right(b)
}
_ => false,
}
}Source§proof fn commutative(a: Self, b: Self)
proof fn commutative(a: Self, b: Self)
Source§proof fn associative(a: Self, b: Self, c: Self)
proof fn associative(a: Self, b: Self, c: Self)
Auto Trait Implementations§
impl<L, R> Freeze for Sum<L, R>
impl<L, R> RefUnwindSafe for Sum<L, R>where
L: RefUnwindSafe,
R: RefUnwindSafe,
impl<L, R> Send for Sum<L, R>
impl<L, R> Sync for Sum<L, R>
impl<L, R> Unpin for Sum<L, R>
impl<L, R> UnwindSafe for Sum<L, R>where
L: UnwindSafe,
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more