QuantityParser

Trait QuantityParser 

Source
pub trait QuantityParser {
    // Required methods
    fn to_milli_cpus(&self) -> Result<Option<i64>, Report>;
    fn to_bytes(&self) -> Result<Option<i64>, Report>;
}
Expand description

This trait works as a parser for the values retrieved from BTreeMap<String, Quantity> collections in k8s_openapi::api::core::v1::Pod and k8s_openapi::api::core::v1::Node

§Errors

The parser will fails if encounters an invalid unit letters or failed to parse String to i64

Required Methods§

Source

fn to_milli_cpus(&self) -> Result<Option<i64>, Report>

This method will parse the cpu resource values returned by Kubernetes Api

let mib = Quantity("1Mi".into());
let ret: i64 = 1048576;
assert_eq!(mib.to_bytes().ok().flatten().unwrap(), ret);
§Errors

The parser will fails if encounters an invalid unit letters or failed to parse String to i64

Source

fn to_bytes(&self) -> Result<Option<i64>, Report>

This method will parse the memory resource values returned by Kubernetes Api

let cpu = Quantity("4".into());
let ret: i64 = 4000;
assert_eq!(cpu.to_milli_cpus().ok().flatten().unwrap(), ret)
§Errors

The parser will fails if encounters an invalid unit letters or failed to parse String to i64

Implementations on Foreign Types§

Source§

impl QuantityParser for Quantity

Implementors§