server/template_state.rs
1//! A stored template as the template-edit form holds it, with the revision
2//! digesting its editable fields.
3
4use crate::artifact_mgmt::user::TemplateDetail;
5use crate::logical::hex_digest;
6
7/// The error text of a template edit whose expected revision no longer matches.
8pub const STALE_TEMPLATE: &str = "the template changed since it was loaded; reload it";
9
10/// Digest of the template's name and source.
11#[must_use]
12pub fn template_revision(name: Option<&str>, source: &str) -> String {
13 hex_digest(vec![format!("template {:?}", (name, source))])
14}
15
16impl TemplateDetail {
17 /// The revision an edit of this template must carry.
18 #[must_use]
19 pub fn revision(&self) -> String {
20 template_revision(self.name.as_deref(), &self.source_text)
21 }
22}