#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct PromptUse {
pub name: String,
pub version: u32,
pub label: Option<String>,
}
impl PromptUse {
pub fn new(name: impl Into<String>, version: u32) -> Self {
Self {
name: name.into(),
version,
label: None,
}
}
pub fn with_label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
}
#[cfg(test)]
mod tests {
use super::PromptUse;
#[test]
fn new_has_no_label_and_with_label_sets_it() {
let used = PromptUse::new("triage", 3);
assert_eq!(
(used.name.as_str(), used.version, used.label.as_deref()),
("triage", 3, None)
);
let labelled = used.clone().with_label("production");
assert_eq!(labelled.label.as_deref(), Some("production"));
assert_eq!(labelled.version, 3);
assert_ne!(used, labelled);
}
}