MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / validate_memory_quantity

Function validate_memory_quantity

crates/openshell-cli/src/run.rs:1716–1742  ·  view source on GitHub ↗
(value: &str)

Source from the content-addressed store, hash-verified

1714}
1715
1716fn validate_memory_quantity(value: &str) -> Result<String> {
1717 let value = value.trim();
1718 if value.is_empty() {
1719 return Err(miette!("--memory must not be empty"));
1720 }
1721
1722 let number_end = value
1723 .find(|ch: char| !ch.is_ascii_digit())
1724 .unwrap_or(value.len());
1725 let (number, suffix) = value.split_at(number_end);
1726 if number.is_empty()
1727 || !matches!(
1728 suffix,
1729 "" | "Ki" | "Mi" | "Gi" | "Ti" | "Pi" | "Ei" | "K" | "M" | "G" | "T" | "P" | "E"
1730 )
1731 {
1732 return Err(miette!(
1733 "invalid --memory value '{value}': expected positive bytes or a quantity such as 512Mi, 4Gi, or 8G"
1734 ));
1735 }
1736
1737 let amount = number.parse::<u128>().into_diagnostic()?;
1738 if amount == 0 {
1739 return Err(miette!("--memory must be greater than zero"));
1740 }
1741 Ok(value.to_string())
1742}
1743
1744async fn finalize_sandbox_create_session(
1745 server: &str,

Callers 1

Calls 2

lenMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected