Crates.io | k8s_quantity_parser |
lib.rs | k8s_quantity_parser |
version | 0.1.0 |
source | src |
created_at | 2022-04-29 17:37:05.835812 |
updated_at | 2022-04-29 23:17:07.703963 |
description | A simple parser for rust k8s_openapi resource Quantity. |
homepage | https://github.com/sombralibre/k8s-quantity-parser |
repository | https://github.com/sombralibre/k8s-quantity-parser |
max_upload_size | |
id | 577451 |
size | 12,402 |
A simple parser for rust k8s_openapi::apimachinery::pkg::api::resource::Quantity
[dependencies]
k8s_quantity_parser = "0.0.1"
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)