Skip to content

Commit cc3ed1f

Browse files
Stebaliensamuelburnham
authored andcommitted
implement hasher using core2
1 parent 456276b commit cc3ed1f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/hasher_impl.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ use crate::hasher::{Digest, Size, StatefulHasher};
33
use core::convert::TryFrom;
44
use generic_array::GenericArray;
55

6+
#[cfg(feature = "std")]
7+
use std::io;
8+
9+
#[cfg(not(feature = "std"))]
10+
use core2::io;
11+
612
macro_rules! derive_digest {
713
($name:ident) => {
814
/// Multihash digest.
@@ -52,14 +58,13 @@ macro_rules! derive_digest {
5258

5359
macro_rules! derive_write {
5460
($name:ident) => {
55-
#[cfg(feature = "std")]
56-
impl<S: Size> std::io::Write for $name<S> {
57-
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
61+
impl<S: Size> io::Write for $name<S> {
62+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
5863
self.update(buf);
5964
Ok(buf.len())
6065
}
6166

62-
fn flush(&mut self) -> std::io::Result<()> {
67+
fn flush(&mut self) -> io::Result<()> {
6368
Ok(())
6469
}
6570
}
@@ -222,14 +227,13 @@ macro_rules! derive_hasher_sha {
222227
}
223228
}
224229

225-
#[cfg(feature = "std")]
226-
impl std::io::Write for $name {
227-
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
230+
impl io::Write for $name {
231+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
228232
self.update(buf);
229233
Ok(buf.len())
230234
}
231235

232-
fn flush(&mut self) -> std::io::Result<()> {
236+
fn flush(&mut self) -> io::Result<()> {
233237
Ok(())
234238
}
235239
}
@@ -325,10 +329,9 @@ pub mod identity {
325329

326330
// A custom implementation is needed as an identity hash also stores the actual size of
327331
// the given digest.
328-
#[cfg(feature = "std")]
329332
fn from_reader<R>(mut r: R) -> Result<Self, Error>
330333
where
331-
R: std::io::Read,
334+
R: io::Read,
332335
{
333336
use crate::multihash::read_u64;
334337

0 commit comments

Comments
 (0)