Skip to content

Commit

Permalink
improve consistency for manifest to/from string
Browse files Browse the repository at this point in the history
  • Loading branch information
asmello committed Sep 19, 2023
1 parent 00303e6 commit 08db98d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ impl From<Manifest> for RawManifest {
fn from(manifest: Manifest) -> Self {
let dependencies: DependencyMap = manifest
.dependencies
.iter()
.map(|dep| (dep.package.to_owned(), dep.manifest.to_owned()))
.into_iter()
.map(|dep| (dep.package, dep.manifest))
.collect();

Self {
Expand Down Expand Up @@ -78,11 +78,6 @@ impl Manifest {
.await
.wrap_err("Failed to write manifest")
}

pub fn as_toml(&self) -> eyre::Result<String> {
toml::to_string_pretty(&RawManifest::from(self.clone()))
.wrap_err("failed to render manifest as TOML")
}
}

impl From<RawManifest> for Manifest {
Expand Down Expand Up @@ -111,6 +106,14 @@ impl TryFrom<String> for Manifest {
}
}

impl TryInto<String> for Manifest {
type Error = toml::ser::Error;

fn try_into(self) -> Result<String, Self::Error> {
toml::to_string_pretty(&RawManifest::from(self))
}
}

/// Manifest format for api packages
#[derive(Debug, Clone, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct PackageManifest {
Expand Down
11 changes: 7 additions & 4 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ impl PackageStore {

let mut archive = tar::Builder::new(Vec::new());

let manifest_bytes = manifest
.as_toml()
.wrap_err("Failed to encode release manifest")?
.into_bytes();
let manifest_bytes = {
let as_str: String = manifest
.clone()
.try_into()
.wrap_err("failed to render manifest as TOML")?;
as_str.into_bytes()
};

let mut header = tar::Header::new_gnu();
header.set_size(
Expand Down

0 comments on commit 08db98d

Please sign in to comment.