pub struct Labels(/* private fields */);Expand description
Structured key-value metadata based on BTreeMap.
Iteration order is stable because labels are stored in key order.
§Example
use solti_model::Labels;
let mut labels = Labels::new();
labels.insert("zone", "eu");
labels.insert("gpu", "h100");
assert_eq!(labels.get("zone"), Some("eu"));
assert!(labels.contains_key("gpu"));Implementations§
Source§impl Labels
impl Labels
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty label map.
§Example
use solti_model::Labels;
let labels = Labels::new();
assert!(labels.is_empty());Sourcepub fn insert<K, V>(&mut self, key: K, val: V) -> &mut Self
pub fn insert<K, V>(&mut self, key: K, val: V) -> &mut Self
Inserts or replaces a label.
§Example
use solti_model::Labels;
let mut labels = Labels::new();
labels.insert("tier", "dev").insert("tier", "prod");
assert_eq!(labels.get("tier"), Some("prod"));Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Returns whether a key exists.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Iterates over labels in key order.
§Example
use solti_model::Labels;
let mut labels = Labels::new();
labels.insert("b", "2");
labels.insert("a", "1");
let pairs: Vec<_> = labels.iter().collect();
assert_eq!(pairs, vec![("a", "1"), ("b", "2")]);Sourcepub fn validate(&self) -> ModelResult<()>
pub fn validate(&self) -> ModelResult<()>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Labels
impl<'de> Deserialize<'de> for Labels
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
impl Eq for Labels
Source§impl<'a> IntoIterator for &'a Labels
impl<'a> IntoIterator for &'a Labels
Source§impl JsonSchema for Labels
impl JsonSchema for Labels
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreimpl StructuralPartialEq for Labels
Auto Trait Implementations§
impl Freeze for Labels
impl RefUnwindSafe for Labels
impl Send for Labels
impl Sync for Labels
impl Unpin for Labels
impl UnsafeUnpin for Labels
impl UnwindSafe for Labels
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