pub enum DependencyId {
SourceFile(ProjectPath),
Asset(ProjectPath),
Bibliography(ProjectPath),
Label(String),
}Expand description
A typed, deterministic identity for one build dependency.
Each variant carries the payload appropriate to its DependencyKind, so
mismatched combinations cannot be constructed. File inputs use the canonical
ProjectPath; labels use their name. The derived Eq/Ord/Hash
make ids usable as keys in deterministic maps and sets; Display gives a
stable kind:payload view for logs and debugging.
§Examples
use mos_cache::{DependencyId, DependencyKind};
let bib = DependencyId::bibliography("./refs.bib")?;
assert_eq!(bib.kind(), DependencyKind::Bibliography);
assert_eq!(bib.to_string(), "bibliography:refs.bib");
assert_eq!(bib.path().map(|p| p.as_str()), Some("refs.bib"));Variants§
SourceFile(ProjectPath)
A .mos source file, identified by its canonical project path.
Asset(ProjectPath)
A referenced asset (such as an image), identified by its canonical path.
Bibliography(ProjectPath)
A bibliography input (such as a .bib file), by its canonical path.
Label(String)
A resolved label, identified by its reference name.
Implementations§
Source§impl DependencyId
impl DependencyId
Sourcepub fn source_file(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
pub fn source_file(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
A .mos source-file dependency.
§Errors
Returns ProjectPathError when path is not a valid project-relative
path.
§Examples
use mos_cache::DependencyId;
assert_eq!(DependencyId::source_file("a.mos")?.to_string(), "source:a.mos");Sourcepub fn asset(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
pub fn asset(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
An asset dependency, such as an image.
§Errors
Returns ProjectPathError when path is not a valid project-relative
path.
§Examples
use mos_cache::DependencyId;
assert_eq!(DependencyId::asset("logo.png")?.to_string(), "asset:logo.png");Sourcepub fn bibliography(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
pub fn bibliography(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
A bibliography-input dependency, such as a .bib file.
§Errors
Returns ProjectPathError when path is not a valid project-relative
path.
§Examples
use mos_cache::DependencyId;
assert_eq!(DependencyId::bibliography("refs.bib")?.to_string(), "bibliography:refs.bib");Sourcepub fn label(name: impl Into<String>) -> Self
pub fn label(name: impl Into<String>) -> Self
A label dependency.
§Examples
use mos_cache::DependencyId;
assert_eq!(DependencyId::label("eq-1").to_string(), "label:eq-1");Sourcepub const fn kind(&self) -> DependencyKind
pub const fn kind(&self) -> DependencyKind
The DependencyKind this id belongs to.
§Examples
use mos_cache::{DependencyId, DependencyKind};
assert_eq!(DependencyId::asset("x.png")?.kind(), DependencyKind::Asset);Sourcepub const fn path(&self) -> Option<&ProjectPath>
pub const fn path(&self) -> Option<&ProjectPath>
The canonical path of a file-backed dependency, or None for labels.
Covers the SourceFile, Asset, and
Bibliography variants uniformly.
§Examples
use mos_cache::DependencyId;
assert_eq!(DependencyId::asset("logo.png")?.path().map(|p| p.as_str()), Some("logo.png"));
assert_eq!(DependencyId::label("eq-1").path(), None);Trait Implementations§
Source§impl Clone for DependencyId
impl Clone for DependencyId
Source§fn clone(&self) -> DependencyId
fn clone(&self) -> DependencyId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DependencyId
impl Debug for DependencyId
Source§impl Display for DependencyId
impl Display for DependencyId
impl Eq for DependencyId
Source§impl Hash for DependencyId
impl Hash for DependencyId
Source§impl Ord for DependencyId
impl Ord for DependencyId
Source§fn cmp(&self, other: &DependencyId) -> Ordering
fn cmp(&self, other: &DependencyId) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for DependencyId
impl PartialEq for DependencyId
Source§fn eq(&self, other: &DependencyId) -> bool
fn eq(&self, other: &DependencyId) -> bool
self and other values to be equal, and is used by ==.