pub trait UpcastSub<H: Sub<Output = H> + Rem<Output = H>>:
Upcast<Higher = H>
+ CheckedSub
+ Copy {
// Provided methods
fn upcast_sub(self, rhs: Self) -> H { ... }
fn upcast_sub_mod(self, rhs: Self, modulo: Self) -> Self { ... }
}
Expand description
Trait to implement upcast sub. (Casting up when type bounds are hit during arithmetic)
Provided Methods§
Sourcefn upcast_sub(self, rhs: Self) -> H
fn upcast_sub(self, rhs: Self) -> H
performs the operatoin self - rhs
and returns value as type H.
let a = i8::MIN;
let b = 10;
let expected = i8::MIN as i16 - 10;
let res = a.upcast_sub(b);
assert_eq!(res, expected);
§Panics
Panics if the operation still exceeds the higher types limit.
ⓘ
let a = 1u8;
let b = 2u8;
let _ = a.upcast_sub(b);
Sourcefn upcast_sub_mod(self, rhs: Self, modulo: Self) -> Self
fn upcast_sub_mod(self, rhs: Self, modulo: Self) -> Self
performs the operation (self - rhs) % modulo
and returns value as type Self.
let a = i8::MIN;
let b = 10;
let modulo = i8::MIN;
let expected = -10;
let res = a.upcast_sub_mod(b, modulo);
assert_eq!(res, expected);
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.