redvault-ai/llama_proxy_man/src/util.rs
Tristan Druyen ad0cd12877
refactor(proxy_man): Org & modularize app
- Introduce new modules: `config.rs`, `error.rs`, `inference_process.rs`, `proxy.rs`, `state.rs`, `util.rs`
- Update `logging.rs` to include static initialization of logging
- Add lib.rs for including in other projects
- Refactor `main.rs` to use new modules and improve code structure
2025-02-10 23:40:27 +01:00

22 lines
567 B
Rust

pub fn parse_size(size_str: &str) -> Option<u64> {
let mut num = String::new();
let mut unit = String::new();
for c in size_str.chars() {
if c.is_digit(10) || c == '.' {
num.push(c);
} else {
unit.push(c);
}
}
let num: f64 = num.parse().ok()?;
let multiplier = match unit.to_lowercase().as_str() {
"g" | "gb" => 1024 * 1024 * 1024,
"m" | "mb" => 1024 * 1024,
"k" | "kb" => 1024,
_ => panic!("Invalid Size"),
};
Some((num * multiplier as f64) as u64)
}