brokkr-broker::utils::matching Rust
Template-to-stack matching utilities.
This module provides functions for validating that a template’s labels and annotations are compatible with a target stack before instantiation.
Structs
brokkr-broker::utils::matching::MatchResult
pub
Derives: Debug, Default, Serialize
Result of a template-to-stack matching operation.
Fields
| Name | Type | Description |
|---|---|---|
matches | bool | Whether the template matches the stack. |
missing_labels | Vec < String > | Labels required by the template that are missing from the stack. |
missing_annotations | Vec < (String , String) > | Annotations required by the template that are missing from the stack. |
Functions
brokkr-broker::utils::matching::template_matches_stack
pub
#![allow(unused)]
fn main() {
fn template_matches_stack (template_labels : & [String] , template_annotations : & [(String , String)] , stack_labels : & [String] , stack_annotations : & [(String , String)] ,) -> MatchResult
}
Check if a template can be instantiated into a stack.
Parameters:
| Name | Type | Description |
|---|---|---|
template_labels | - | Labels attached to the template |
template_annotations | - | Annotations attached to the template (key-value pairs) |
stack_labels | - | Labels attached to the target stack |
stack_annotations | - | Annotations attached to the target stack (key-value pairs) |
Returns:
A MatchResult indicating whether the template matches and details about any missing labels or annotations.
Source
#![allow(unused)]
fn main() {
pub fn template_matches_stack(
template_labels: &[String],
template_annotations: &[(String, String)],
stack_labels: &[String],
stack_annotations: &[(String, String)],
) -> MatchResult {
// If template has no labels/annotations, it matches everything (go anywhere)
if template_labels.is_empty() && template_annotations.is_empty() {
return MatchResult {
matches: true,
missing_labels: Vec::new(),
missing_annotations: Vec::new(),
};
}
// Check all template labels exist on stack
let missing_labels: Vec<String> = template_labels
.iter()
.filter(|tl| !stack_labels.contains(tl))
.cloned()
.collect();
// Check all template annotations exist on stack (exact key-value match)
let missing_annotations: Vec<(String, String)> = template_annotations
.iter()
.filter(|ta| !stack_annotations.contains(ta))
.cloned()
.collect();
MatchResult {
matches: missing_labels.is_empty() && missing_annotations.is_empty(),
missing_labels,
missing_annotations,
}
}
}