Skip to content

Commit 3e7eccb

Browse files
chore: refactor InputManifest::write
Signed-off-by: Andrew Lilley Brinker <[email protected]>
1 parent 94f63ac commit 3e7eccb

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

omnibor/src/input_manifest.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@ mod input_manifest_builder;
44
mod manifest_source;
55
mod manifest_source_async;
66

7-
use std::io::BufWriter;
8-
97
pub use input_manifest_builder::InputManifestBuilder;
108
pub use manifest_source::ManifestSource;
119
pub use manifest_source_async::ManifestSourceAsync;
1210

13-
use crate::{hash_algorithm::Sha256, IdentifyAsync};
14-
1511
use {
1612
crate::{
1713
artifact_id::ArtifactId,
1814
error::InputManifestError,
19-
hash_algorithm::HashAlgorithm,
15+
hash_algorithm::{HashAlgorithm, Sha256},
2016
object_type::{Blob, ObjectType},
2117
storage::Storage,
22-
Identify,
18+
Identify, IdentifyAsync,
2319
},
2420
std::{
2521
cmp::Ordering,
2622
fmt::{Debug, Display, Formatter, Result as FmtResult},
27-
io::Write,
23+
io::{BufWriter, Write},
2824
},
2925
};
3026

@@ -218,13 +214,15 @@ impl<H: HashAlgorithm> InputManifest<H> {
218214
write!(out, "{}", self.header())?;
219215

220216
for relation in &self.inputs {
221-
write!(out, "{}", relation.artifact.as_hex())?;
222-
223-
if let Some(manifest_aid) = relation.manifest {
224-
write!(out, " manifest {}", manifest_aid.as_hex())?;
217+
let target_hex = relation.artifact.as_hex();
218+
219+
match relation.manifest {
220+
Some(manifest_aid) => {
221+
let manifest_hex = manifest_aid.as_hex();
222+
writeln!(out, "{target_hex} manifest {manifest_hex}")?
223+
}
224+
None => writeln!(out, "{target_hex}")?,
225225
}
226-
227-
writeln!(out)?;
228226
}
229227

230228
Ok(())
@@ -242,7 +240,8 @@ impl<H: HashAlgorithm> Debug for InputManifest<H> {
242240

243241
impl<H: HashAlgorithm> Display for InputManifest<H> {
244242
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
245-
let str = String::from_utf8(self.as_bytes().to_vec()).unwrap();
243+
// PANIC SAFETY: Always guaranteed to be valid UTF-8.
244+
let str = String::from_utf8(self.as_bytes()).unwrap();
246245
write!(f, "{str}")
247246
}
248247
}

0 commit comments

Comments
 (0)