Struct vstd::arithmetic::overflow::CheckedU32
source · pub struct CheckedU32 { /* private fields */ }
Expand description
This struct represents a $uty
value that can overflow. The i
field
is a ghost value that represents the true value, while the v
field
is None
when the value has overflowed and Some(x)
when the value
x
fits in a $uty
.
Implementations§
source§impl CheckedU32
impl CheckedU32
sourcepub closed spec fn spec_new(v: u32) -> CheckedU32
pub closed spec fn spec_new(v: u32) -> CheckedU32
Creates a new $cty
instance from a $uty
value.
Ensures the internal representation matches the provided value.
sourcepub exec fn new(v: u32) -> result : Self
pub exec fn new(v: u32) -> result : Self
result@ == v,
Creates a new $cty
instance from a $uty
value.
Ensures the internal representation matches the provided value.
sourcepub exec fn new_overflowed(Ghost(i): Ghost<int>) -> result : Self
pub exec fn new_overflowed(Ghost(i): Ghost<int>) -> result : Self
i > u32::MAX,
ensuresresult@ == i,
Creates a new $cty
instance with an overflowed value.
Requires the provided value to be greater than $uty::MAX
.
Ensures the internal representation matches the provided value.
sourcepub open spec fn spec_is_overflowed(&self) -> bool
pub open spec fn spec_is_overflowed(&self) -> bool
{ self@ > u32::MAX }
Checks if the $cty
instance is overflowed.
Returns true if the value is greater than $uty::MAX
.
sourcepub exec fn is_overflowed(&self) -> result : bool
pub exec fn is_overflowed(&self) -> result : bool
result == self.spec_is_overflowed(),
Checks if the $cty
instance is overflowed.
Returns true if the value is greater than $uty::MAX
.
sourcepub exec fn unwrap(&self) -> result : u32
pub exec fn unwrap(&self) -> result : u32
!self.is_overflowed(),
ensuresresult == self@,
Unwraps the $cty
instance to get the $uty
value.
Requires the instance to not be overflowed.
Ensures the returned value matches the internal representation.
sourcepub exec fn to_option(&self) -> result : Option<u32>
pub exec fn to_option(&self) -> result : Option<u32>
match result {
Some(v) => self@ == v && v <= u32::MAX,
None => self@ > u32::MAX,
},
Converts the $cty
instance to an Option<$uty>
.
Ensures the returned option matches the internal representation.
sourcepub exec fn add_value(&self, v2: u32) -> result : Self
pub exec fn add_value(&self, v2: u32) -> result : Self
result@ == self@ + v2,
Adds a $uty
value to the $cty
instance.
Ensures the resulting value matches the sum of
the internal representation and the provided
value.
sourcepub exec fn add_checked(&self, v2: &CheckedU32) -> result : Self
pub exec fn add_checked(&self, v2: &CheckedU32) -> result : Self
result@ == self@ + v2@,
Adds another $cty
instance to the current
instance. Ensures the resulting value matches
the sum of the internal representations of
both instances.
sourcepub exec fn mul_value(&self, v2: u32) -> result : Self
pub exec fn mul_value(&self, v2: u32) -> result : Self
result@ == self@ as int * v2 as int,
Multiplies the $cty
instance by a $uty
value. Ensures the resulting value matches the
product of the internal representation and the
provided value.
sourcepub exec fn mul_checked(&self, v2: &Self) -> result : Self
pub exec fn mul_checked(&self, v2: &Self) -> result : Self
result@ == self@ as int * v2@ as int,
Multiplies the $cty
instance by another $cty
instance.
Ensures the resulting value matches the product of the internal
representations of both instances.
Trait Implementations§
source§impl Clone for CheckedU32
impl Clone for CheckedU32
Auto Trait Implementations§
impl Freeze for CheckedU32
impl RefUnwindSafe for CheckedU32
impl Send for CheckedU32
impl Sync for CheckedU32
impl Unpin for CheckedU32
impl UnwindSafe for CheckedU32
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)