1
//! A stored template as the template-edit form holds it, with the revision
2
//! digesting its editable fields.
3

            
4
use crate::artifact_mgmt::user::TemplateDetail;
5
use crate::logical::hex_digest;
6

            
7
/// The error text of a template edit whose expected revision no longer matches.
8
pub 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]
12
7391
pub fn template_revision(name: Option<&str>, source: &str) -> String {
13
7391
    hex_digest(vec![format!("template {:?}", (name, source))])
14
7391
}
15

            
16
impl TemplateDetail {
17
    /// The revision an edit of this template must carry.
18
    #[must_use]
19
5045
    pub fn revision(&self) -> String {
20
5045
        template_revision(self.name.as_deref(), &self.source_text)
21
5045
    }
22
}