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