1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::path::{Path, PathBuf};
use crate::Manifest;
#[cfg(all(feature = "toml", feature = "serde", feature = "thiserror"))]
use crate::TomlReadError;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Package {
manifest: Manifest,
path: PathBuf,
}
impl Package {
#[cfg(all(feature = "toml", feature = "serde", feature = "thiserror"))]
pub fn from_path(path: PathBuf) -> Result<Self, TomlReadError> {
Ok(Self {
manifest: Manifest::from_package_path(&path)?,
path,
})
}
pub fn from_manifest_and_path(manifest: Manifest, path: PathBuf) -> Self {
Self { manifest, path }
}
pub fn manifest(&self) -> &Manifest {
&self.manifest
}
pub fn path(&self) -> &Path {
&self.path
}
pub fn relative_readme_path(&self) -> Option<&Path> {
self.manifest.relative_readme_path(&self.path)
}
pub fn default_relative_readme_path(&self) -> Option<&Path> {
Manifest::default_readme_filename(&self.path)
}
}