Skip to main content

Signed

Trait Signed 

Source
pub trait Signed {
    // Required method
    fn sign(&self) -> Sign;

    // Provided methods
    fn is_positive(&self) -> bool { ... }
    fn is_negative(&self) -> bool { ... }
}
Expand description

This trait marks the number is signed.

Notice that the negative zeros (of f32 and f64) are still considered to have a positive sign.

§Examples

assert_eq!((-2).sign(), Sign::Negative);
assert_eq!((-2.4).sign(), Sign::Negative);
assert_eq!((0.).sign(), Sign::Positive);

assert!(2.is_positive());
assert!((-2.4).is_negative());
assert!((0.).is_positive());

Required Methods§

Source

fn sign(&self) -> Sign

Provided Methods§

Source

fn is_positive(&self) -> bool

Source

fn is_negative(&self) -> bool

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Signed for f32

Source§

fn sign(&self) -> Sign

Source§

impl Signed for f64

Source§

fn sign(&self) -> Sign

Source§

impl Signed for i8

Source§

fn sign(&self) -> Sign

Source§

impl Signed for i16

Source§

fn sign(&self) -> Sign

Source§

impl Signed for i32

Source§

fn sign(&self) -> Sign

Source§

impl Signed for i64

Source§

fn sign(&self) -> Sign

Source§

impl Signed for i128

Source§

fn sign(&self) -> Sign

Source§

impl Signed for isize

Source§

fn sign(&self) -> Sign

Implementors§