#quantity #parser #k8s-openapi

k8s_quantity_parser

A simple parser for rust k8s_openapi resource Quantity

3 unstable releases

0.1.0 Apr 29, 2022
0.0.2 Apr 29, 2022
0.0.1 Apr 29, 2022

#10 in #quantity

MIT license

11KB
197 lines

k8s-quantity-parser

A simple parser for rust k8s_openapi::apimachinery::pkg::api::resource::Quantity

Install

[dependencies]
k8s_quantity_parser = "0.0.1"

Usage

use k8s_openapi::apimachinery::pkg::api::resource::Quantity;
use k8s_quantity_parser::QuantityParser;

// Parse memory values to bytes
let mib = Quantity("1Mi".into());
let ret: i64 = 1048576;
assert_eq!(mib.to_bytes().ok().flatten().unwrap(), ret);

// Parse cpu values to milli units of CPU.
let cpu = Quantity("4".into());
let ret: i64 = 4000;
assert_eq!(cpu.to_milli_cpus().ok().flatten().unwrap(), ret)

Dependencies

~43MB
~685K SLoC