Skip to main content

Sign

Enum Sign 

Source
pub enum Sign {
    Negative = -1,
    Zero = 0,
    Positive = 1,
}
Expand description

๐Ÿ“ The three-valued sign of a number: negative (โˆ’1), zero (0), or positive (+1).


๐Ÿ“num/quant


This enum models the mathematical signum function and is useful when representing or manipulating a valueโ€™s sign independently of its magnitude.

Variantsยง

ยง

Negative = -1

A negative sign (-).

ยง

Zero = 0

The zero sign (0). (The default)

ยง

Positive = 1

A positive sign (+).

Implementationsยง

Sourceยง

impl Sign

Source

pub const fn eq(self, other: Self) -> bool

True if self == other.

Source

pub const fn is_negative(self) -> bool

True if self is Negative.

Source

pub const fn is_positive(self) -> bool

True if self is Positive.

Source

pub const fn is_zero(self) -> bool

True if self is Zero.

Source

pub const fn is_nonzero(self) -> bool

True if self is not Zero.

Source

pub const fn invert(self) -> Self

Flips Positive โ†” Negative, keeps Zero.

Source

pub const fn same_direction(self, other: Self) -> bool

Returns true if both have the same non-zero direction.

Source

pub const fn combine(self, other: Self) -> Self

Multiplies two signs with zero-dominance.

Source

pub const fn pow(self, n: u32) -> Self

Raises the sign to n with zero-dominance: oddโ†’same, evenโ†’Positive.

Source

pub const fn abs(self) -> Self

Converts Negativeโ†’Positive; keeps Zero/Positive.

Source

pub const fn neg_abs(self) -> Self

Converts Positiveโ†’Negative; keeps Zero/Negative.

Source

pub fn fold<I: IntoIterator<Item = Sign>>(iter: I) -> Self

Combines all signs in iter with zero-dominance.

Source

pub const fn fold_slice(slice: &[Sign]) -> Self

Combines all signs in slice with zero-dominance.

Trait Implementationsยง

Sourceยง

impl Clone for Sign

Sourceยง

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl ConstInitCore for Sign

Sourceยง

const INIT: Self = Sign::Zero

No sign.

Sourceยง

impl Copy for Sign

Sourceยง

impl Debug for Sign

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Default for Sign

Sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl Eq for Sign

Sourceยง

impl From<Sign> for i8

Sourceยง

fn from(s: Sign) -> i8

Returns 0 if Zero, 1 if Positive and -1 if Negative.

Sourceยง

impl From<Sign> for i16

Sourceยง

fn from(s: Sign) -> i16

Returns 0 if Zero, 1 if Positive and -1 if Negative.

Sourceยง

impl From<Sign> for i32

Sourceยง

fn from(s: Sign) -> i32

Returns 0 if Zero, 1 if Positive and -1 if Negative.

Sourceยง

impl From<Sign> for i64

Sourceยง

fn from(s: Sign) -> i64

Returns 0 if Zero, 1 if Positive and -1 if Negative.

Sourceยง

impl From<Sign> for i128

Sourceยง

fn from(s: Sign) -> i128

Returns 0 if Zero, 1 if Positive and -1 if Negative.

Sourceยง

impl From<Sign> for isize

Sourceยง

fn from(s: Sign) -> isize

Returns 0 if Zero, 1 if Positive and -1 if Negative.

Sourceยง

impl From<Sign> for f32

Sourceยง

fn from(s: Sign) -> f32

Returns 0.0 if Zero, 1.0 if Positive and -1.0 if Negative.

Sourceยง

impl From<Sign> for f64

Sourceยง

fn from(s: Sign) -> f64

Returns 0.0 if Zero, 1.0 if Positive and -1.0 if Negative.

Sourceยง

impl From<bool> for Sign

Sourceยง

fn from(n: bool) -> Sign

Returns Positive if true and Negative if false.

Sourceยง

impl From<f32> for Sign

Sourceยง

fn from(n: f32) -> Sign

Returns Zero if 0.0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<f64> for Sign

Sourceยง

fn from(n: f64) -> Sign

Returns Zero if 0.0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<i8> for Sign

Sourceยง

fn from(n: i8) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<i16> for Sign

Sourceยง

fn from(n: i16) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<i32> for Sign

Sourceยง

fn from(n: i32) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<i64> for Sign

Sourceยง

fn from(n: i64) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<i128> for Sign

Sourceยง

fn from(n: i128) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<isize> for Sign

Sourceยง

fn from(n: isize) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<u8> for Sign

Sourceยง

fn from(n: u8) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<u16> for Sign

Sourceยง

fn from(n: u16) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<u32> for Sign

Sourceยง

fn from(n: u32) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<u64> for Sign

Sourceยง

fn from(n: u64) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<u128> for Sign

Sourceยง

fn from(n: u128) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl From<usize> for Sign

Sourceยง

fn from(n: usize) -> Sign

Returns Zero if 0, Positive if > 0 and Negative if < 0.

Sourceยง

impl Hash for Sign

Sourceยง

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 ยท Sourceยง

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Sourceยง

impl PartialEq for Sign

Sourceยง

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Sourceยง

impl StructuralPartialEq for Sign

Sourceยง

impl TryFrom<Sign> for u8

Sourceยง

fn try_from(s: Sign) -> Result<u8, InvalidValue> โ“˜

Returns 0 if Zero and 1 if Positive.

ยงErrors

Returns InvalidValue if the sign is Negative.

Sourceยง

type Error = InvalidValue

The type returned in the event of a conversion error.
Sourceยง

impl TryFrom<Sign> for u16

Sourceยง

fn try_from(s: Sign) -> Result<u16, InvalidValue> โ“˜

Returns 0 if Zero and 1 if Positive.

ยงErrors

Returns InvalidValue if the sign is Negative.

Sourceยง

type Error = InvalidValue

The type returned in the event of a conversion error.
Sourceยง

impl TryFrom<Sign> for u32

Sourceยง

fn try_from(s: Sign) -> Result<u32, InvalidValue> โ“˜

Returns 0 if Zero and 1 if Positive.

ยงErrors

Returns InvalidValue if the sign is Negative.

Sourceยง

type Error = InvalidValue

The type returned in the event of a conversion error.
Sourceยง

impl TryFrom<Sign> for u64

Sourceยง

fn try_from(s: Sign) -> Result<u64, InvalidValue> โ“˜

Returns 0 if Zero and 1 if Positive.

ยงErrors

Returns InvalidValue if the sign is Negative.

Sourceยง

type Error = InvalidValue

The type returned in the event of a conversion error.
Sourceยง

impl TryFrom<Sign> for u128

Sourceยง

fn try_from(s: Sign) -> Result<u128, InvalidValue> โ“˜

Returns 0 if Zero and 1 if Positive.

ยงErrors

Returns InvalidValue if the sign is Negative.

Sourceยง

type Error = InvalidValue

The type returned in the event of a conversion error.
Sourceยง

impl TryFrom<Sign> for usize

Sourceยง

fn try_from(s: Sign) -> Result<usize, InvalidValue> โ“˜

Returns 0 if Zero and 1 if Positive.

ยงErrors

Returns InvalidValue if the sign is Negative.

Sourceยง

type Error = InvalidValue

The type returned in the event of a conversion error.
Sourceยง

impl TryFrom<Sign> for bool

Sourceยง

fn try_from(s: Sign) -> Result<bool, InvalidValue> โ“˜

Returns true if Zero and false if Negative.

ยงErrors

Returns InvalidValue if the sign is Zero.

Sourceยง

type Error = InvalidValue

The type returned in the event of a conversion error.

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> ByteSized for T

Sourceยง

const BYTE_ALIGN: usize = _

The alignment of this type in bytes.
Sourceยง

const BYTE_SIZE: usize = _

The size of this type in bytes.
Sourceยง

fn byte_align(&self) -> usize

Returns the alignment of this type in bytes.
Sourceยง

fn byte_size(&self) -> usize

Returns the size of this type in bytes. Read more
Sourceยง

fn ptr_size_ratio(&self) -> [usize; 2]

Returns the size ratio between Ptr::BYTES and BYTE_SIZE. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Hook for T

Sourceยง

fn hook<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Hooks a mutation step into the value and returns it. Read more
Sourceยง

fn tap<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Taps into the value for observation and returns it unchanged. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T, R> Morph<R> for T
where T: ?Sized,

Sourceยง

fn morph<F>(self, f: F) -> R
where F: FnOnce(Self) -> R, Self: Sized,

Morphs the value into a new one and returns it. Read more
Sourceยง

fn morph_ref<F>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Morphs the value by shared reference and returns the result. Read more
Sourceยง

fn morph_mut<F>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Morphs the value by exclusive reference and returns the result. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = !

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, !> โ“˜

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> โ“˜

Performs the conversion.