Trait UnwrapOverflowOpsUnsigned

Source
pub unsafe trait UnwrapOverflowOpsUnsigned: UnwrapOverflowOps {
    type Signed: UnwrapOverflowOpsSigned;

    // Required method
    fn unwrap_add_signed(self, arg: Self::Signed) -> Self;
}
Expand description

An extension trait for unsigned arithmetic operations that are guaranteed to panic on overflow.

This implements operations specific to unsigned integers, the UnwrapOverflowOps trait is for operations supported by all integers.

This is a polyfill for the strict_overflow_ops feature.

These operations are only implemented for primitive integer types.

§Safety

These methods are guarenteed to check for overflow, regardless of compiler settings and cfg!(...) flags.

The correctness of these methods can be relied upon for memory safety.

Required Associated Types§

Source

type Signed: UnwrapOverflowOpsSigned

The signed integer type with the same size

Required Methods§

Source

fn unwrap_add_signed(self, arg: Self::Signed) -> Self

Strict addition with a signed integer. Computes self + rhs, panicking if overflow occurred.

This is a polyfill for the strict_overflow_ops feature, which offers equivalent methods for each primitive integer type (ex. u32::strict_add_signed).

§Panics

This function will always panic on overflow, regardless of whether overflow checks are enabled.

§Examples

Basic usage:

use unwrap_overflow_ops::*;
assert_eq!(1u32.unwrap_add_signed(2), 3);

The following panics because of overflow:

use unwrap_overflow_ops::*;
let _ = 1u32.unwrap_add_signed(-2);

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 UnwrapOverflowOpsUnsigned for u8

Source§

type Signed = i8

Source§

fn unwrap_add_signed(self, other: Self::Signed) -> Self

Source§

impl UnwrapOverflowOpsUnsigned for u16

Source§

type Signed = i16

Source§

fn unwrap_add_signed(self, other: Self::Signed) -> Self

Source§

impl UnwrapOverflowOpsUnsigned for u32

Source§

type Signed = i32

Source§

fn unwrap_add_signed(self, other: Self::Signed) -> Self

Source§

impl UnwrapOverflowOpsUnsigned for u64

Source§

type Signed = i64

Source§

fn unwrap_add_signed(self, other: Self::Signed) -> Self

Source§

impl UnwrapOverflowOpsUnsigned for u128

Source§

type Signed = i128

Source§

fn unwrap_add_signed(self, other: Self::Signed) -> Self

Source§

impl UnwrapOverflowOpsUnsigned for usize

Source§

type Signed = isize

Source§

fn unwrap_add_signed(self, other: Self::Signed) -> Self

Implementors§