pub struct Version {
pub language: Language,
pub requires: BTreeSet<String>,
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.
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)
\n
<source>A scope contains no whitespace and the source comes last, so the framing is unambiguous without escaping anything.
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(),
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());Sourcepub fn document(&self, name: &str) -> VersionDocument
pub fn document(&self, name: &str) -> VersionDocument
The JSON face of this version under name.
Trait Implementations§
impl Eq for Version
impl StructuralPartialEq for Version
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnsafeUnpin for Version
impl UnwindSafe for Version
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more