pub struct Frontmatter { /* private fields */ }Expand description
A concept’s frontmatter: an ordered key/value mapping with typed accessors for the well-known OKF fields.
Implementations§
Source§impl Frontmatter
impl Frontmatter
Sourcepub const fn from_mapping(map: Mapping) -> Self
pub const fn from_mapping(map: Mapping) -> Self
Wraps an existing mapping.
Sourcepub const fn as_mapping(&self) -> &Mapping
pub const fn as_mapping(&self) -> &Mapping
Borrows the underlying ordered mapping.
Sourcepub const fn as_mapping_mut(&mut self) -> &mut Mapping
pub const fn as_mapping_mut(&mut self) -> &mut Mapping
Mutably borrows the underlying ordered mapping.
Sourcepub fn into_mapping(self) -> Mapping
pub fn into_mapping(self) -> Mapping
Consumes the wrapper, returning the underlying mapping.
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Raw value for an arbitrary key (including producer extensions).
Sourcepub fn set(&mut self, key: impl Into<String>, value: Value)
pub fn set(&mut self, key: impl Into<String>, value: Value)
Sets a raw value for a key, preserving position if it already exists.
Sourcepub fn reorder_preferred(&mut self)
pub fn reorder_preferred(&mut self)
Reorders the keys into PREFERRED_KEY_ORDER, leaving every other key
after them in its current relative order.
A port of the reference implementation’s _reorder_frontmatter, which it
applies whenever it writes a concept document; call this before
Document::serialize to produce
frontmatter laid out the same way. No key is added, dropped, or
rewritten, so only the serialized order changes.
Sourcepub fn type_(&self) -> Option<Cow<'_, str>>
pub fn type_(&self) -> Option<Cow<'_, str>>
The required type field (§4.1). None if absent or not a scalar.
Non-string scalars (type: 42) are coerced to their display form, the
way the reference’s str(fm.get("type")) does, rather than read as
None: the spec calls type “a short string”, so a non-string value
is a producer deviation, but a consumer still gets something to
route on rather than treating the concept as typeless.
Sourcepub fn description(&self) -> Option<Cow<'_, str>>
pub fn description(&self) -> Option<Cow<'_, str>>
The optional one-line description.
Sourcepub fn resource(&self) -> Option<Cow<'_, str>>
pub fn resource(&self) -> Option<Cow<'_, str>>
The optional resource URI for the underlying asset.
The optional tags list. Non-string elements are coerced to their
display form; a non-sequence tags value yields an empty vector.
Sourcepub fn sources(&self) -> Vec<Source>
pub fn sources(&self) -> Vec<Source>
The sources entries: the materials this concept derives from.
Sourcepub fn usage_window(&self) -> Option<UsageWindow>
pub fn usage_window(&self) -> Option<UsageWindow>
The shared usage_window that frames every sources[].usage_count.
Sourcepub fn generated(&self) -> Option<Generated>
pub fn generated(&self) -> Option<Generated>
The generated block: how the current content was produced.
Sourcepub fn verified(&self) -> Vec<Verification>
pub fn verified(&self) -> Vec<Verification>
The verified events: who or what has confirmed this content.
A bare { by, at } mapping is returned as a one-element list, as §5.2
requires.
Sourcepub fn latest_verification(&self) -> Option<Verification>
pub fn latest_verification(&self) -> Option<Verification>
The verification with the latest parseable at (§5.2).
Sourcepub fn trust_tier(&self) -> TrustTier
pub fn trust_tier(&self) -> TrustTier
The trust tier derived from verified (§5.3).
Sourcepub fn content_changed_at(&self) -> Option<DateTimeField>
pub fn content_changed_at(&self) -> Option<DateTimeField>
When the content last meaningfully changed: generated.at (§5.2),
falling back to a legacy v0.1 timestamp when generated is absent, as
§13.1 permits.
Sourcepub fn timestamp(&self) -> Option<Cow<'_, str>>
pub fn timestamp(&self) -> Option<Cow<'_, str>>
The legacy v0.1 timestamp field, superseded by generated.at (§13.1).
Prefer Frontmatter::content_changed_at, which reads generated.at
first and falls back to this.
Sourcepub fn status(&self) -> Status
pub fn status(&self) -> Status
The lifecycle status. An absent key is Status::Stable (§5.4).
Sourcepub fn stale_after(&self) -> Option<DateField>
pub fn stale_after(&self) -> Option<DateField>
The stale_after date, on and after which the content is stale (§5.5).
Sourcepub fn is_stale_on(&self, today: Date) -> bool
pub fn is_stale_on(&self, today: Date) -> bool
Whether the concept is stale on today: today >= stale_after (§5.5).
A concept with no (or an unreadable) stale_after is never stale.
A datetime-valued stale_after is compared on its date part, as
DateField::effective_date explains.
Sourcepub fn is_attested_computation(&self) -> bool
pub fn is_attested_computation(&self) -> bool
true when type is Attested Computation (§10.1).
Sourcepub fn runtime(&self) -> Option<Cow<'_, str>>
pub fn runtime(&self) -> Option<Cow<'_, str>>
The runtime: how to run the computation, and so what parameters
mean. REQUIRED on an Attested Computation concept.
Sourcepub fn parameters(&self) -> Vec<Parameter>
pub fn parameters(&self) -> Vec<Parameter>
The declared parameters an agent may fill.
Sourcepub fn computation(&self) -> Option<Cow<'_, str>>
pub fn computation(&self) -> Option<Cow<'_, str>>
The computation path, when the computation lives in a file rather than
a body block (§10.3).
Sourcepub fn executor(&self) -> Option<Executor>
pub fn executor(&self) -> Option<Executor>
The executor: how the computation is run, and what a receipt carries.
Sourcepub fn attester(&self) -> Option<Attester>
pub fn attester(&self) -> Option<Attester>
The attester: deterministic code that turns a receipt into a verdict.
Sourcepub fn path_fields(&self) -> Vec<(&'static str, String)>
pub fn path_fields(&self) -> Vec<(&'static str, String)>
The path-valued frontmatter fields present (§6.2), as
(field name, raw value).
sources[].resource is deliberately excluded: it may be a scope
descriptor rather than a path (§5.1). Use
Source::resource_kind to
filter those yourself.
Sourcepub fn extension_keys(&self) -> Vec<&str>
pub fn extension_keys(&self) -> Vec<&str>
Returns the keys present that are not well-known OKF fields, i.e. the producer-defined extension keys consumers must preserve (§4.1).
Sourcepub fn legacy_keys(&self) -> Vec<&str>
pub fn legacy_keys(&self) -> Vec<&str>
Returns the legacy v0.1 keys present that v0.2 supersedes (§13.1).
Trait Implementations§
Source§impl Clone for Frontmatter
impl Clone for Frontmatter
Source§fn clone(&self) -> Frontmatter
fn clone(&self) -> Frontmatter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more