Struct Number

Source
pub struct Number {
    pub u8: Option<u8>,
    pub u16: Option<u16>,
    pub u32: Option<u32>,
    pub u64: Option<u64>,
    pub u128: Option<u128>,
    pub i8: Option<i8>,
    pub i16: Option<i16>,
    pub i32: Option<i32>,
    pub i64: Option<i64>,
    pub i128: Option<i128>,
    pub f32: Option<f32>,
    pub f64: Option<f64>,
}
Expand description

A struct representing a number that can store different numeric types.

§Examples

let mut num = Number::default();
num.set_u8(42);
assert_eq!(num.get_u8(), Some(42));

Fields§

§u8: Option<u8>§u16: Option<u16>§u32: Option<u32>§u64: Option<u64>§u128: Option<u128>§i8: Option<i8>§i16: Option<i16>§i32: Option<i32>§i64: Option<i64>§i128: Option<i128>§f32: Option<f32>§f64: Option<f64>

Implementations§

Source§

impl Number

Source

pub fn clean(&mut self) -> &mut Number

Empties the Number struct by removing any stored value.

§Returns

A mutable reference to the Number struct after removing any stored value.

§Examples
let mut num = Number::default();
num.set_u64(42);
num.clean();
assert_eq!(num.is_number(), false);

Trait Implementations§

Source§

impl Clone for Number

Source§

fn clone(&self) -> Number

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Number

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Number

Source§

fn default() -> Number

Returns the “default value” for a type. Read more
Source§

impl Display for Number

Implements the Display trait for the Number struct.

Provides a human-readable representation of a Number instance by matching its fields and converting the value to a string.

Source§

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

Formats the Number struct for display by returning a string representation of the stored value.

§Arguments
  • f - A mutable reference to a std::fmt::Formatter used for formatting the display.
§Returns

A std::fmt::Result containing the result of the formatting operation.

§Examples
let mut num = Number::default();
num.set_f64(42.0);
println!("{}", num); // Output: 42.0
Source§

impl From<f32> for Number

Converts an f32 value to a Number.

Source§

fn from(i: f32) -> Number

Converts to this type from the input type.
Source§

impl From<f64> for Number

Converts an f64 value to a Number.

Source§

fn from(i: f64) -> Number

Converts to this type from the input type.
Source§

impl From<i128> for Number

Converts an i128 value to a Number.

Source§

fn from(i: i128) -> Number

Converts to this type from the input type.
Source§

impl From<i16> for Number

Converts an i16 value to a Number.

Source§

fn from(i: i16) -> Number

Converts to this type from the input type.
Source§

impl From<i32> for Number

Converts an i32 value to a Number.

Source§

fn from(i: i32) -> Number

Converts to this type from the input type.
Source§

impl From<i64> for Number

Converts an i64 value to a Number.

Source§

fn from(i: i64) -> Number

Converts to this type from the input type.
Source§

impl From<i8> for Number

Converts an i8 value to a Number.

Source§

fn from(i: i8) -> Number

Converts to this type from the input type.
Source§

impl From<isize> for Number

Source§

fn from(i: isize) -> Number

Converts to this type from the input type.
Source§

impl From<u128> for Number

Converts an u128 value to a Number.

Source§

fn from(i: u128) -> Number

Converts to this type from the input type.
Source§

impl From<u16> for Number

Converts an u16 value to a Number.

Source§

fn from(i: u16) -> Number

Converts to this type from the input type.
Source§

impl From<u32> for Number

Converts an u32 value to a Number.

Source§

fn from(i: u32) -> Number

Converts to this type from the input type.
Source§

impl From<u64> for Number

Converts an u8 value to a Number.

Source§

fn from(i: u64) -> Number

Converts to this type from the input type.
Source§

impl From<u8> for Number

Converts an u8 value to a Number.

Source§

fn from(i: u8) -> Number

Converts to this type from the input type.
Source§

impl From<usize> for Number

Converts an usize value to a Number.

Source§

fn from(i: usize) -> Number

Converts to this type from the input type.
Source§

impl NumberBehavior for Number

Source§

fn is_integer(&self) -> bool

Checks if the stored number is an integer.

§Returns

true if the stored number is an integer, false otherwise.

§Examples
let mut num = Number::default();
num.set_i32(42);
assert_eq!(num.is_integer(), true);
Source§

fn set_u8(&mut self, value: u8)

Sets the value of the Number struct to the given u8 value. Read more
Source§

fn set_u16(&mut self, value: u16)

Source§

fn set_u32(&mut self, value: u32)

Source§

fn set_u64(&mut self, value: u64)

Source§

fn set_u128(&mut self, value: u128)

Source§

fn set_i8(&mut self, value: i8)

Source§

fn set_i16(&mut self, value: i16)

Source§

fn set_i32(&mut self, value: i32)

Source§

fn set_i64(&mut self, value: i64)

Source§

fn set_i128(&mut self, value: i128)

Source§

fn set_f32(&mut self, value: f32)

Source§

fn set_f64(&mut self, value: f64)

Source§

fn get_u8(&self) -> Option<u8>

Returns the u8 value stored in the Number struct, if any. Read more
Source§

fn get_u16(&self) -> Option<u16>

Source§

fn get_u32(&self) -> Option<u32>

Source§

fn get_u64(&self) -> Option<u64>

Source§

fn get_u128(&self) -> Option<u128>

Source§

fn get_i8(&self) -> Option<i8>

Source§

fn get_i16(&self) -> Option<i16>

Source§

fn get_i32(&self) -> Option<i32>

Source§

fn get_i64(&self) -> Option<i64>

Source§

fn get_i128(&self) -> Option<i128>

Source§

fn get_f32(&self) -> Option<f32>

Source§

fn get_f64(&self) -> Option<f64>

Source§

fn get_u8_unsafe(&self) -> u8

Returns the u8 value stored in the Number struct, without checking if it exists. Read more
Source§

fn get_u16_unsafe(&self) -> u16

Source§

fn get_u32_unsafe(&self) -> u32

Source§

fn get_u64_unsafe(&self) -> u64

Source§

fn get_u128_unsafe(&self) -> u128

Source§

fn get_i8_unsafe(&self) -> i8

Source§

fn get_i16_unsafe(&self) -> i16

Source§

fn get_i32_unsafe(&self) -> i32

Source§

fn get_i64_unsafe(&self) -> i64

Source§

fn get_i128_unsafe(&self) -> i128

Source§

fn get_f32_unsafe(&self) -> f32

Source§

fn get_f64_unsafe(&self) -> f64

Source§

fn is_i8(&self) -> bool

Checks if the stored number is of type i8. Read more
Source§

fn is_i16(&self) -> bool

Source§

fn is_i32(&self) -> bool

Source§

fn is_i64(&self) -> bool

Source§

fn is_i128(&self) -> bool

Source§

fn is_u8(&self) -> bool

Source§

fn is_u16(&self) -> bool

Source§

fn is_u32(&self) -> bool

Source§

fn is_u64(&self) -> bool

Source§

fn is_u128(&self) -> bool

Source§

fn is_f32(&self) -> bool

Source§

fn is_f64(&self) -> bool

Source§

fn is_number(&self) -> bool

Checks if the Number struct contains any value. Read more
Source§

fn is_float(&self) -> bool

Source§

fn is_signed(&self) -> bool

Source§

fn is_unsigned(&self) -> bool

Source§

fn is_zero(&self) -> bool

Source§

fn is_positive(&self) -> bool

Source§

fn is_negative(&self) -> bool

Source§

fn number_type(&self) -> NumberType

fn is_integer(&self) -> bool { /* … */ } Determines the type of number stored in the Number struct. Read more
Source§

fn to_f64(&self) -> Option<f64>

Source§

fn to_i64(&self) -> Option<i64>

Source§

fn to_u64(&self) -> Option<u64>

Converts the Number struct to numeric types. Read more
Source§

impl PartialEq for Number

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Number

Source§

fn partial_cmp(&self, other: &Number) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToValueBehavior for Number

Source§

fn to_value(&self) -> Value

Converts a type into a Value.
Source§

impl TryFrom<&str> for Number

Converts a &str value to a Number if it can be parsed as a valid number.

§Arguments

  • value - A string slice containing a numeric value to be converted.

§Returns

A Result<Self, Self::Error> containing the Number if the conversion was successful or an error if the conversion failed.

§Examples

let num = Number::try_from("42").unwrap();
assert_eq!(num.get_i32(), Some(42));

let num = Number::try_from("42.0").unwrap();
assert_eq!(num.get_f64(), Some(42.0));

let num = Number::try_from("invalid");
assert!(num.is_err());
Source§

type Error = Error

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

fn try_from(value: &str) -> Result<Number, <Number as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Number

Converts a String value to a Number if it can be parsed as a valid number.

§Arguments

  • value - A String containing a numeric value to be converted.

§Returns

A Result<Self, Self::Error> containing the Number if the conversion was successful or an error if the conversion failed.

§Examples

let num = Number::try_from("42".to_string()).unwrap();
assert_eq!(num.get_i32(), Some(42));

let num = Number::try_from("42.0".to_string()).unwrap();
assert_eq!(num.get_f64(), Some(42.0));

let num = Number::try_from("invalid".to_string());
assert!(num.is_err());
Source§

type Error = Error

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

fn try_from(value: String) -> Result<Number, <Number as TryFrom<String>>::Error>

Performs the conversion.
Source§

impl PrimitiveType for Number

Source§

impl StructuralPartialEq for Number

Auto Trait Implementations§

§

impl Freeze for Number

§

impl RefUnwindSafe for Number

§

impl Send for Number

§

impl Sync for Number

§

impl Unpin for Number

§

impl UnwindSafe for Number

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> 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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T