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§
Trait Implementations§
Source§impl Display for Number
Implements the Display trait for the Number struct.
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>
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 astd::fmt::Formatterused 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.0Source§impl NumberBehavior for Number
impl NumberBehavior for Number
Source§fn is_integer(&self) -> bool
fn is_integer(&self) -> bool
fn set_u16(&mut self, value: u16)
fn set_u32(&mut self, value: u32)
fn set_u64(&mut self, value: u64)
fn set_u128(&mut self, value: u128)
fn set_i8(&mut self, value: i8)
fn set_i16(&mut self, value: i16)
fn set_i32(&mut self, value: i32)
fn set_i64(&mut self, value: i64)
fn set_i128(&mut self, value: i128)
fn set_f32(&mut self, value: f32)
fn set_f64(&mut self, value: f64)
fn get_u16(&self) -> Option<u16>
fn get_u32(&self) -> Option<u32>
fn get_u64(&self) -> Option<u64>
fn get_u128(&self) -> Option<u128>
fn get_i8(&self) -> Option<i8>
fn get_i16(&self) -> Option<i16>
fn get_i32(&self) -> Option<i32>
fn get_i64(&self) -> Option<i64>
fn get_i128(&self) -> Option<i128>
fn get_f32(&self) -> Option<f32>
fn get_f64(&self) -> Option<f64>
Source§fn get_u8_unsafe(&self) -> u8
fn get_u8_unsafe(&self) -> u8
fn get_u16_unsafe(&self) -> u16
fn get_u32_unsafe(&self) -> u32
fn get_u64_unsafe(&self) -> u64
fn get_u128_unsafe(&self) -> u128
fn get_i8_unsafe(&self) -> i8
fn get_i16_unsafe(&self) -> i16
fn get_i32_unsafe(&self) -> i32
fn get_i64_unsafe(&self) -> i64
fn get_i128_unsafe(&self) -> i128
fn get_f32_unsafe(&self) -> f32
fn get_f64_unsafe(&self) -> f64
fn is_i16(&self) -> bool
fn is_i32(&self) -> bool
fn is_i64(&self) -> bool
fn is_i128(&self) -> bool
fn is_u8(&self) -> bool
fn is_u16(&self) -> bool
fn is_u32(&self) -> bool
fn is_u64(&self) -> bool
fn is_u128(&self) -> bool
fn is_f32(&self) -> bool
fn is_f64(&self) -> bool
fn is_float(&self) -> bool
fn is_signed(&self) -> bool
fn is_unsigned(&self) -> bool
fn is_zero(&self) -> bool
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
Source§fn number_type(&self) -> NumberType
fn number_type(&self) -> NumberType
Number struct. Read morefn to_f64(&self) -> Option<f64>
fn to_i64(&self) -> Option<i64>
Source§impl PartialOrd for Number
impl PartialOrd for Number
Source§impl ToValueBehavior for Number
impl ToValueBehavior for Number
Source§impl TryFrom<&str> for Number
Converts a &str value to a Number if it can be parsed as a valid number.
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§impl TryFrom<String> for Number
Converts a String value to a Number if it can be parsed as a valid number.
impl TryFrom<String> for Number
Converts a String value to a Number if it can be parsed as a valid number.
§Arguments
value- AStringcontaining 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());impl PrimitiveType for Number
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request