pub struct ParsedQuantity { /* private fields */ }Expand description
ParsedQuantity represents a parsed Kubernetes quantity.
use k8s_openapi::apimachinery::pkg::api::resource::Quantity;
use kube_quantity::{ParseQuantityError, ParsedQuantity};
// Kubernetes quantity
let k8s_quantity = Quantity("1Ki".to_string());
// Try parsing k8s quantity
let quantity: Result<ParsedQuantity, ParseQuantityError> = k8s_quantity.try_into();
assert_eq!(quantity.unwrap().to_string(), "1Ki");Implementations§
Source§impl ParsedQuantity
impl ParsedQuantity
Sourcepub fn to_string_with_precision(&self, precision: u32) -> String
pub fn to_string_with_precision(&self, precision: u32) -> String
Returns the value of the quantity as a string with the specified number of decimal points for fractional portion. Additionally it performs normalization, i.e., strips any trailing zero’s from a value and converts -0 to 0.
When a number is halfway between two others, it is rounded toward the nearest number that is away from zero. e.g. 6.4 -> 6, 6.5 -> 7, -6.5 -> -7
use k8s_openapi::apimachinery::pkg::api::resource::Quantity;
use kube_quantity::ParsedQuantity;
let k_quantity: ParsedQuantity = Quantity("1k".to_string()).try_into().unwrap();
let ki_quantity: ParsedQuantity = Quantity("1Ki".to_string()).try_into().unwrap();
let q3 = k_quantity + ki_quantity;
assert_eq!(q3.to_string_with_precision(3), "2.024k");
assert_eq!(q3.to_string_with_precision(2), "2.02k");
assert_eq!(q3.to_string_with_precision(1), "2k");
assert_eq!(q3.to_string_with_precision(0), "2k");Sourcepub fn to_bytes_f64(&self) -> Option<f64>
pub fn to_bytes_f64(&self) -> Option<f64>
Returns the value of the quantity as an f64.
use k8s_openapi::apimachinery::pkg::api::resource::Quantity;
use kube_quantity::{ParseQuantityError, ParsedQuantity};
// Kubernetes quantity
let k8s_quantity = Quantity("1Ki".to_string());
// Try parsing k8s quantity
let quantity: Result<ParsedQuantity, ParseQuantityError> = k8s_quantity.try_into();
assert_eq!(quantity.unwrap().to_bytes_f64(), Some(1024.0));Sourcepub fn to_bytes_f32(&self) -> Option<f32>
pub fn to_bytes_f32(&self) -> Option<f32>
Returns the value of the quantity as an f32.
Sourcepub fn to_bytes_i128(&self) -> Option<i128>
pub fn to_bytes_i128(&self) -> Option<i128>
Returns the value of the quantity as an i128.
Sourcepub fn to_bytes_i64(&self) -> Option<i64>
pub fn to_bytes_i64(&self) -> Option<i64>
Returns the value of the quantity as an i64.
Sourcepub fn to_bytes_i32(&self) -> Option<i32>
pub fn to_bytes_i32(&self) -> Option<i32>
Returns the value of the quantity as an i32.
Sourcepub fn to_bytes_i16(&self) -> Option<i16>
pub fn to_bytes_i16(&self) -> Option<i16>
Returns the value of the quantity as an i16.
Sourcepub fn to_bytes_i8(&self) -> Option<i8>
pub fn to_bytes_i8(&self) -> Option<i8>
Returns the value of the quantity as an i8. This will only work if the scale is 0.
Sourcepub fn to_bytes_isize(&self) -> Option<isize>
pub fn to_bytes_isize(&self) -> Option<isize>
Returns the value of the quantity as an isize.
Sourcepub fn to_bytes_u128(&self) -> Option<u128>
pub fn to_bytes_u128(&self) -> Option<u128>
Returns the value of the quantity as an u128.
Sourcepub fn to_bytes_u64(&self) -> Option<u64>
pub fn to_bytes_u64(&self) -> Option<u64>
Returns the value of the quantity as an u64.
Sourcepub fn to_bytes_u32(&self) -> Option<u32>
pub fn to_bytes_u32(&self) -> Option<u32>
Returns the value of the quantity as an u32.
Sourcepub fn to_bytes_u16(&self) -> Option<u16>
pub fn to_bytes_u16(&self) -> Option<u16>
Returns the value of the quantity as an u16.
Sourcepub fn to_bytes_u8(&self) -> Option<u8>
pub fn to_bytes_u8(&self) -> Option<u8>
Returns the value of the quantity as an u8. This will only work if the scale is 0.
Sourcepub fn to_bytes_usize(&self) -> Option<usize>
pub fn to_bytes_usize(&self) -> Option<usize>
Returns the value of the quantity as an usize.
Trait Implementations§
Source§impl Add for ParsedQuantity
impl Add for ParsedQuantity
Source§impl AddAssign for ParsedQuantity
impl AddAssign for ParsedQuantity
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Clone for ParsedQuantity
impl Clone for ParsedQuantity
Source§fn clone(&self) -> ParsedQuantity
fn clone(&self) -> ParsedQuantity
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParsedQuantity
impl Debug for ParsedQuantity
Source§impl Default for ParsedQuantity
impl Default for ParsedQuantity
Source§fn default() -> ParsedQuantity
fn default() -> ParsedQuantity
Source§impl Display for ParsedQuantity
impl Display for ParsedQuantity
Source§impl<T> Div<T> for ParsedQuantity
impl<T> Div<T> for ParsedQuantity
Source§impl<T> DivAssign<T> for ParsedQuantity
impl<T> DivAssign<T> for ParsedQuantity
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl From<Decimal> for ParsedQuantity
impl From<Decimal> for ParsedQuantity
Source§impl From<ParsedQuantity> for Quantity
impl From<ParsedQuantity> for Quantity
Source§fn from(value: ParsedQuantity) -> Self
fn from(value: ParsedQuantity) -> Self
Source§impl<T> Mul<T> for ParsedQuantity
impl<T> Mul<T> for ParsedQuantity
Source§impl<T> MulAssign<T> for ParsedQuantity
impl<T> MulAssign<T> for ParsedQuantity
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl Neg for ParsedQuantity
impl Neg for ParsedQuantity
Source§impl Ord for ParsedQuantity
impl Ord for ParsedQuantity
Source§impl PartialEq for ParsedQuantity
impl PartialEq for ParsedQuantity
Source§impl PartialOrd for ParsedQuantity
impl PartialOrd for ParsedQuantity
Source§impl Sub for ParsedQuantity
impl Sub for ParsedQuantity
Source§impl SubAssign for ParsedQuantity
impl SubAssign for ParsedQuantity
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more