ploys/package/manifest/
mod.rs1pub mod cargo;
7mod dependency;
8mod error;
9mod members;
10
11use std::fmt::{self, Display};
12
13use strum::{EnumIs, EnumTryAs};
14
15pub use self::cargo::CargoManifest;
16pub use self::dependency::{Dependencies, DependenciesMut, DependencyMut, DependencyRef};
17pub use self::error::Error;
18pub use self::members::Members;
19
20use super::PackageKind;
21
22#[derive(Clone, Debug, PartialEq, Eq, EnumIs, EnumTryAs)]
24pub enum Manifest {
25 Cargo(CargoManifest),
27}
28
29impl Manifest {
30 pub fn new_cargo(name: impl Into<String>) -> Self {
32 Self::Cargo(CargoManifest::new_package(name))
33 }
34
35 pub fn package_kind(&self) -> PackageKind {
37 match self {
38 Self::Cargo(_) => PackageKind::Cargo,
39 }
40 }
41
42 pub fn members(&self) -> Result<Members, Error> {
44 match self {
45 Self::Cargo(cargo) => Ok(cargo.members()?),
46 }
47 }
48
49 pub fn from_bytes(kind: PackageKind, bytes: &[u8]) -> Result<Self, Error> {
51 match kind {
52 PackageKind::Cargo => Ok(Self::Cargo(CargoManifest::from_bytes(bytes)?)),
53 }
54 }
55}
56
57impl Manifest {
58 pub fn get_dependency(&self, name: impl AsRef<str>) -> Option<DependencyRef<'_>> {
60 match self {
61 Self::Cargo(cargo) => cargo.get_dependency(name).map(DependencyRef::Cargo),
62 }
63 }
64
65 pub fn get_dependency_mut(&mut self, name: impl AsRef<str>) -> Option<DependencyMut<'_>> {
67 match self {
68 Self::Cargo(cargo) => cargo.get_dependency_mut(name).map(DependencyMut::Cargo),
69 }
70 }
71
72 pub fn dependencies(&self) -> Dependencies<'_> {
74 match self {
75 Self::Cargo(cargo) => Dependencies::Cargo(cargo.dependencies()),
76 }
77 }
78
79 pub fn dependencies_mut(&mut self) -> DependenciesMut<'_> {
81 match self {
82 Self::Cargo(cargo) => DependenciesMut::Cargo(cargo.dependencies_mut()),
83 }
84 }
85}
86
87impl Manifest {
88 pub fn get_dev_dependency(&self, name: impl AsRef<str>) -> Option<DependencyRef<'_>> {
90 match self {
91 Self::Cargo(cargo) => cargo.get_dev_dependency(name).map(DependencyRef::Cargo),
92 }
93 }
94
95 pub fn get_dev_dependency_mut(&mut self, name: impl AsRef<str>) -> Option<DependencyMut<'_>> {
97 match self {
98 Self::Cargo(cargo) => cargo.get_dev_dependency_mut(name).map(DependencyMut::Cargo),
99 }
100 }
101
102 pub fn dev_dependencies(&self) -> Dependencies<'_> {
104 match self {
105 Self::Cargo(cargo) => Dependencies::Cargo(cargo.dev_dependencies()),
106 }
107 }
108
109 pub fn dev_dependencies_mut(&mut self) -> DependenciesMut<'_> {
111 match self {
112 Self::Cargo(cargo) => DependenciesMut::Cargo(cargo.dev_dependencies_mut()),
113 }
114 }
115}
116
117impl Manifest {
118 pub fn get_build_dependency(&self, name: impl AsRef<str>) -> Option<DependencyRef<'_>> {
120 match self {
121 Self::Cargo(cargo) => cargo.get_build_dependency(name).map(DependencyRef::Cargo),
122 }
123 }
124
125 pub fn get_build_dependency_mut(&mut self, name: impl AsRef<str>) -> Option<DependencyMut<'_>> {
127 match self {
128 Self::Cargo(cargo) => cargo
129 .get_build_dependency_mut(name)
130 .map(DependencyMut::Cargo),
131 }
132 }
133
134 pub fn build_dependencies(&self) -> Dependencies<'_> {
136 match self {
137 Self::Cargo(cargo) => Dependencies::Cargo(cargo.build_dependencies()),
138 }
139 }
140
141 pub fn build_dependencies_mut(&mut self) -> DependenciesMut<'_> {
143 match self {
144 Self::Cargo(cargo) => DependenciesMut::Cargo(cargo.build_dependencies_mut()),
145 }
146 }
147}
148
149impl Display for Manifest {
150 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151 match self {
152 Self::Cargo(cargo) => Display::fmt(cargo, f),
153 }
154 }
155}