integer_result

Trait Ext

Source
pub trait Ext
where Self: Sized + Eq + Ord,
{ // Provided methods fn ok_less(self, val: Self) -> Result<Self, Self> { ... } fn ok_equal(self, val: Self) -> Result<Self, Self> { ... } fn ok_greater(self, val: Self) -> Result<Self, Self> { ... } }
Expand description

use this trait to access ok_less, ok_equal, and ok_greater for all primitive and non-zero integer types.

Provided Methods§

Source

fn ok_less(self, val: Self) -> Result<Self, Self>

Returns an Ok holding the integer if less than the other integer val. Otherwise, returns and Err holding the integer.

§Examples
use integer_result::Ext;

assert_eq!(1.ok_less(2), Ok(1));
assert_eq!(1.ok_less(0), Err(1));
Source

fn ok_equal(self, val: Self) -> Result<Self, Self>

Returns an Ok holding the integer if equal to the other integer val. Otherwise, returns an Err holding the integer.

§Examples
use integer_result::Ext;

assert_eq!(1.ok_equal(1), Ok(1));
assert_eq!(1.ok_equal(0), Err(1));
Source

fn ok_greater(self, val: Self) -> Result<Self, Self>

Returns an Ok holding the integer if greater than the other integer val. Otherwise, returns and Err holding the integer.

§Examples
use integer_result::Ext;

assert_eq!(1.ok_greater(-1), Ok(1));
assert_eq!(1.ok_greater(1), Err(1));

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.

Implementations on Foreign Types§

Source§

impl Ext for i8

Source§

impl Ext for i16

Source§

impl Ext for i32

Source§

impl Ext for i64

Source§

impl Ext for i128

Source§

impl Ext for isize

Source§

impl Ext for u8

Source§

impl Ext for u16

Source§

impl Ext for u32

Source§

impl Ext for u64

Source§

impl Ext for u128

Source§

impl Ext for usize

Source§

impl Ext for NonZeroI8

Source§

impl Ext for NonZeroI16

Source§

impl Ext for NonZeroI32

Source§

impl Ext for NonZeroI64

Source§

impl Ext for NonZeroI128

Source§

impl Ext for NonZeroIsize

Source§

impl Ext for NonZeroU8

Source§

impl Ext for NonZeroU16

Source§

impl Ext for NonZeroU32

Source§

impl Ext for NonZeroU64

Source§

impl Ext for NonZeroU128

Source§

impl Ext for NonZeroUsize

Implementors§