Skip to content

Commit 3fb4ae3

Browse files
committed
Resolve feedback
1 parent cc3ed1f commit 3fb4ae3

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub enum Error {
2323
impl core::fmt::Display for Error {
2424
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
2525
match self {
26-
//#[cfg(feature = "std")]
2726
Self::Io(err) => write!(f, "{}", err),
2827
Self::UnsupportedCode(code) => write!(f, "Unsupported multihash code {}.", code),
2928
Self::InvalidSize(size) => write!(f, "Invalid multihash size {}.", size),

src/multihash.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::hasher::{Digest, Size};
22
use crate::Error;
3-
#[cfg(not(feature = "std"))]
3+
#[cfg(feature = "alloc")]
44
use alloc::vec::Vec;
55
use core::convert::TryFrom;
66

@@ -160,9 +160,11 @@ impl<S: Size> Multihash<S> {
160160
write_multihash(w, self.code(), self.size(), self.digest())
161161
}
162162

163+
164+
#[cfg(any(feature = "std", feature = "alloc"))]
163165
/// Returns the bytes of a multihash.
164166
pub fn to_bytes(&self) -> Vec<u8> {
165-
let mut bytes: Vec<u8> = Vec::with_capacity(self.size().into());
167+
let mut bytes = Vec::with_capacity(self.size().into());
166168
self.write(&mut bytes)
167169
.expect("writing to a vec should never fail");
168170
bytes
@@ -178,6 +180,7 @@ impl<S: Size> core::hash::Hash for Multihash<S> {
178180
}
179181
}
180182

183+
#[cfg(any(feature = "std", feature = "alloc"))]
181184
impl<S: Size> From<Multihash<S>> for Vec<u8> {
182185
fn from(multihash: Multihash<S>) -> Self {
183186
multihash.to_bytes()
@@ -284,14 +287,8 @@ where
284287
R: io::Read,
285288
S: Size,
286289
{
287-
let code = match read_u64(&mut r) {
288-
Ok(c) => c,
289-
Err(e) => return Err(e.into()),
290-
};
291-
let size = match read_u64(&mut r) {
292-
Ok(s) => s,
293-
Err(e) => return Err(e.into()),
294-
};
290+
let code = read_u64(&mut r)?;
291+
let size = read_u64(&mut r)?;
295292

296293
if size > S::to_u64() || size > u8::MAX as u64 {
297294
return Err(Error::InvalidSize(size));

0 commit comments

Comments
 (0)