pub struct Version {
pub language: Language,
pub requires: BTreeSet<String>,
pub budget: Option<u64>,
pub source: String,
}Expand description
One immutable version: the content a digest names.
Fields§
§language: LanguageIts language.
requires: BTreeSet<String>The capability it declares it needs, its language’s included.
budget: Option<u64>The store time budget it declares, in milliseconds (budget= at publish), or None
for the store’s base. Part of the content, so a republish that changes it is a new
version (see crate::authority::effective_budget for what a run gets).
source: StringThe source text.
Implementations§
Source§impl Version
impl Version
Sourcepub fn canonical(&self) -> Vec<u8> ⓘ
pub fn canonical(&self) -> Vec<u8> ⓘ
The bytes the digest is taken over:
ikigai-script/1\n
language <language>\n
requires <scope>\n (one line per scope, sorted)
budget <milliseconds>\n (only when it declares one)
\n
<source>A scope contains no whitespace and the source comes last, so the framing is
unambiguous without escaping anything. A version declaring no budget frames exactly as
one did before budget existed, so every digest already stored is unchanged.
Sourcepub fn digest(&self) -> String
pub fn digest(&self) -> String
The version’s name: sha256: and 64 lowercase hex digits over canonical.
use ikigai_script::model::{Language, Version};
let v = Version {
language: Language::Lisp,
requires: ["urn:cap:lisp".to_string()].into_iter().collect(),
budget: None,
source: "(+ 1 2)".to_string(),
};
let digest = v.digest();
assert!(digest.starts_with("sha256:"));
assert_eq!(digest.len(), "sha256:".len() + 64);
assert!(digest["sha256:".len()..].bytes().all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase()));
// Content-addressed: the same content is the same version.
assert_eq!(digest, v.clone().digest());
// A declared budget is content too.
let budgeted = Version { budget: Some(900), ..v.clone() };
assert_ne!(budgeted.digest(), digest);Sourcepub fn document(&self, name: &str) -> VersionDocument
pub fn document(&self, name: &str) -> VersionDocument
The JSON face of this version under name.