pub struct Tags { /* private fields */ }Expand description
A lightweight, sorted collection of key-value string tags.
Tags are stored in a SmallVec with inline capacity for up to 16 entries,
avoiding heap allocation for typical use cases. Keys are kept sorted
for efficient binary search lookup.
Both keys and values use SmolStr for small string optimization,
providing zero-allocation storage for strings ≤22 bytes.
§Example
ⓘ
let mut tags = Tags::new();
tags.set("env", "prod");
tags.set("region", "us-west");
assert_eq!(tags.get("env"), Some("prod"));
assert!(tags.contains_key("region"));Implementations§
Source§impl Tags
impl Tags
Sourcepub fn set(&mut self, key: impl Into<SmolStr>, value: impl Into<SmolStr>)
pub fn set(&mut self, key: impl Into<SmolStr>, value: impl Into<SmolStr>)
Set a tag value. If the key exists, the value is updated.
Keys are kept sorted for efficient lookup.
Sourcepub fn get(&self, key: &str) -> Option<&str>
pub fn get(&self, key: &str) -> Option<&str>
Get a tag value by key.
Returns None if the key doesn’t exist.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Check if a key exists in the tags.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tags
impl<'de> Deserialize<'de> for Tags
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Tags
impl RefUnwindSafe for Tags
impl Send for Tags
impl Sync for Tags
impl Unpin for Tags
impl UnwindSafe for Tags
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
Mutably borrows from an owned value. Read more