pint_pkg/source/
member.rs1use crate::{
4 manifest::{ManifestFile, ManifestFileError},
5 source,
6};
7use serde::{Deserialize, Serialize};
8use std::{
9 fmt,
10 path::{Path, PathBuf},
11};
12
13#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
15pub struct Source(pub(super) PathBuf);
16
17#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
19pub struct Pinned;
20
21impl source::Pin for Source {
22 type Pinned = Pinned;
23 type Error = core::convert::Infallible;
24 fn pin(&self, _ctx: source::PinCtx) -> Result<(Self::Pinned, PathBuf), Self::Error> {
25 Ok((Pinned, self.0.clone()))
26 }
27}
28
29impl source::Fetch for Pinned {
30 type Error = ManifestFileError;
31 fn fetch(&self, _ctx: source::PinCtx, local: &Path) -> Result<ManifestFile, Self::Error> {
32 let manifest_path = local.join(ManifestFile::FILE_NAME);
33 let manifest = ManifestFile::from_path(&manifest_path)?;
34 Ok(manifest)
35 }
36}
37
38impl source::DepPath for Pinned {
39 type Error = core::convert::Infallible;
40 fn dep_path(&self, _name: &str) -> Result<source::DependencyPath, Self::Error> {
41 Ok(source::DependencyPath::Member)
42 }
43}
44
45impl fmt::Display for Pinned {
46 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47 write!(f, "member")
48 }
49}
50
51impl From<Pinned> for source::Pinned {
52 fn from(p: Pinned) -> Self {
53 source::Pinned::Member(p)
54 }
55}