pub struct Label(/* private fields */);Expand description
A grammar-checked string property.
Construction is only possible through Label::sanitize. The grammar
admits catalog and repository identifiers (Qwen2.5-7B-Instruct-Q4_K_M,
Qwen/Qwen2.5-7B) and rejects anything path-shaped, whitespace-bearing,
or over-long.
use mesh_llm_analytics::Label;
assert!(Label::sanitize("Qwen/Qwen2.5-7B").is_some());
assert!(Label::sanitize("/Users/dan/models/private.gguf").is_none());Implementations§
Source§impl Label
impl Label
Sourcepub fn sanitize(value: &str) -> Option<Self>
pub fn sanitize(value: &str) -> Option<Self>
Accept value only if it matches the label grammar.
The grammar is: ASCII alphanumerics plus ., -, _, +, and at
most one interior /; no leading or trailing separator; no ..; at
most [MAX_LABEL_LEN] characters.
+ is admitted for semver build metadata (0.76.0+gABCDEF.dirty),
which is the version string this crate reports about itself.
Sourcepub fn slug(value: &str) -> Option<Self>
pub fn slug(value: &str) -> Option<Self>
Normalize a human-readable device name into a label.
Hardware probes return names like Apple M4 Max or
NVIDIA GeForce RTX 4090, which Label::sanitize rejects for
containing spaces.
Collapsing separators is dangerous on its own: it would turn
/home/dan/my model.gguf into the perfectly valid-looking
home-dan-my-model.gguf, laundering a path past the grammar. Two
extra rules prevent that, and they are why this is a distinct
constructor rather than a pre-pass on sanitize:
- Input containing a path separator is refused outright, never normalized.
- The result is capped at [
MAX_SLUG_SEGMENTS] segments and [MAX_SLUG_LEN] characters, which every real device name fits and prose does not.
use mesh_llm_analytics::Label;
assert_eq!(Label::slug("Apple M4 Max").unwrap().as_str(), "apple-m4-max");
assert!(Label::slug("/Users/dan/models/private.gguf").is_none());Sourcepub fn redacted() -> Self
pub fn redacted() -> Self
A label for a value that failed sanitization, so counts stay complete.
Sourcepub fn sanitize_or_redact(value: &str) -> Self
pub fn sanitize_or_redact(value: &str) -> Self
Sanitize value, falling back to Label::redacted.
Use this when the count matters more than the identity, so an unrecognized model name still contributes to totals without leaking whatever the user actually typed.
Sourcepub fn slug_or_redact(value: &str) -> Self
pub fn slug_or_redact(value: &str) -> Self
Slug value, falling back to Label::redacted.
pub fn as_str(&self) -> &str
Trait Implementations§
impl Eq for Label
Source§impl Ord for Label
impl Ord for Label
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Label
impl PartialOrd for Label
impl StructuralPartialEq for Label
Auto Trait Implementations§
impl Freeze for Label
impl RefUnwindSafe for Label
impl Send for Label
impl Sync for Label
impl Unpin for Label
impl UnsafeUnpin for Label
impl UnwindSafe for Label
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more