funty

Trait Signed

Source
pub trait Signed: Integral + Neg {
    // Required methods
    fn checked_abs(self) -> Option<Self>;
    fn wrapping_abs(self) -> Self;
    fn overflowing_abs(self) -> (Self, bool);
    fn abs(self) -> Self;
    fn signum(self) -> Self;
    fn is_positive(self) -> bool;
    fn is_negative(self) -> bool;
}
Expand description

Declare that a type is a signed integer.

Required Methods§

Source

fn checked_abs(self) -> Option<Self>

Checked absolute value. Computes self.abs(), returning None if self == MIN.

Source

fn wrapping_abs(self) -> Self

Wrapping (modular) absolute value. Computes self.abs(), wrapping around at the boundary of the type.

The only case where such wrapping can occur is when one takes the absolute value of the negative minimal value for the type this is a positive value that is too large to represent in the type. In such a case, this function returns MIN itself.

Source

fn overflowing_abs(self) -> (Self, bool)

Computes the absolute value of self.

Returns a tuple of the absolute version of self along with a boolean indicating whether an overflow happened. If self is the minimum value (e.g., iN::MIN for values of type iN), then the minimum value will be returned again and true will be returned for an overflow happening.

Source

fn abs(self) -> Self

§Overflow behavior

The absolute value of iN::min_value() cannot be represented as an iN, and attempting to calculate it will cause an overflow. This means that code in debug mode will trigger a panic on this case and optimized code will return iN::min_value() without a panic.

Source

fn signum(self) -> Self

Returns a number representing sign of self.

  • 0 if the number is zero
  • 1 if the number is positive
  • -1 if the number is negative
Source

fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

Source

fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

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 Signed for i8

Source§

fn checked_abs(self) -> Option<Self>

Source§

fn wrapping_abs(self) -> Self

Source§

fn overflowing_abs(self) -> (Self, bool)

Source§

fn abs(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn is_positive(self) -> bool

Source§

fn is_negative(self) -> bool

Source§

impl Signed for i16

Source§

fn checked_abs(self) -> Option<Self>

Source§

fn wrapping_abs(self) -> Self

Source§

fn overflowing_abs(self) -> (Self, bool)

Source§

fn abs(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn is_positive(self) -> bool

Source§

fn is_negative(self) -> bool

Source§

impl Signed for i32

Source§

fn checked_abs(self) -> Option<Self>

Source§

fn wrapping_abs(self) -> Self

Source§

fn overflowing_abs(self) -> (Self, bool)

Source§

fn abs(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn is_positive(self) -> bool

Source§

fn is_negative(self) -> bool

Source§

impl Signed for i64

Source§

fn checked_abs(self) -> Option<Self>

Source§

fn wrapping_abs(self) -> Self

Source§

fn overflowing_abs(self) -> (Self, bool)

Source§

fn abs(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn is_positive(self) -> bool

Source§

fn is_negative(self) -> bool

Source§

impl Signed for i128

Source§

fn checked_abs(self) -> Option<Self>

Source§

fn wrapping_abs(self) -> Self

Source§

fn overflowing_abs(self) -> (Self, bool)

Source§

fn abs(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn is_positive(self) -> bool

Source§

fn is_negative(self) -> bool

Source§

impl Signed for isize

Source§

fn checked_abs(self) -> Option<Self>

Source§

fn wrapping_abs(self) -> Self

Source§

fn overflowing_abs(self) -> (Self, bool)

Source§

fn abs(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn is_positive(self) -> bool

Source§

fn is_negative(self) -> bool

Implementors§