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

Function normalize_compute_driver_name

crates/openshell-core/src/config.rs:78–92  ·  view source on GitHub ↗

Normalize a configured compute driver name. Built-in driver names and custom remote driver names share the same selection namespace. The normalized value is lowercase ASCII and may contain letters, digits, `-`, and `_`.

(value: &str)

Source from the content-addressed store, hash-verified

76/// selection namespace. The normalized value is lowercase ASCII and may contain
77/// letters, digits, `-`, and `_`.
78pub fn normalize_compute_driver_name(value: &str) -> Result<String, String> {
79 let value = value.trim();
80 if value.is_empty() {
81 return Err("compute driver name cannot be empty".to_string());
82 }
83 if !value
84 .bytes()
85 .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_'))
86 {
87 return Err(format!(
88 "invalid compute driver name '{value}'. use ASCII letters, digits, '-' or '_'"
89 ));
90 }
91 Ok(value.to_ascii_lowercase())
92}
93
94impl fmt::Display for ComputeDriverKind {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

Calls 1

is_emptyMethod · 0.45