Skip to main content

DependencyId

Enum DependencyId 

Source
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

Source

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");
Source

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");
Source

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");
Source

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");
Source

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);
Source

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

Source§

fn clone(&self) -> DependencyId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DependencyId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DependencyId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Renders a stable kind:payload view. Equality and hashing use the exact payloads, which this string faithfully reflects for file paths (already canonical) and labels.

Source§

impl Eq for DependencyId

Source§

impl Hash for DependencyId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DependencyId

Source§

fn cmp(&self, other: &DependencyId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DependencyId

Source§

fn eq(&self, other: &DependencyId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for DependencyId

Source§

fn partial_cmp(&self, other: &DependencyId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for DependencyId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.