Skip to content

Commit 056c2a9

Browse files
committed
impl Write for no_std_io::Write
1 parent f9ef162 commit 056c2a9

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

codetable/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rust-version = "1.81"
1111

1212
[features]
1313
default = ["std"]
14-
std = ["blake2b_simd?/std", "blake2s_simd?/std", "blake3?/std", "digest/alloc", "sha1?/alloc", "sha2?/alloc", "sha3?/alloc", "ripemd?/alloc", "multihash-derive/std"]
14+
std = ["blake2b_simd?/std", "blake2s_simd?/std", "blake3?/std", "digest/alloc", "sha1?/alloc", "sha2?/alloc", "sha3?/alloc", "ripemd?/alloc", "multihash/std", "multihash-derive/std"]
1515
arb = ["dep:arbitrary", "std"]
1616
sha1 = ["dep:sha1"]
1717
sha2 = ["dep:sha2"]
@@ -31,6 +31,7 @@ sha2 = { version = "0.11", default-features = false, optional = true }
3131
sha3 = { version = "0.11", default-features = false, optional = true }
3232
strobe-rs = { version = "0.13", default-features = false, optional = true }
3333
ripemd = { version = "0.2", default-features = false, optional = true }
34+
multihash = { version = "0.19.4", path = "..", default-features = false }
3435
multihash-derive = { version = "0.9.2", path = "../derive", default-features = false }
3536
digest = { version = "0.11", default-features = false }
3637
serde = { version = "1.0.158", features = ["derive"], default-features = false, optional = true }

codetable/src/hasher_impl.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ macro_rules! derive_write {
1919
Ok(())
2020
}
2121
}
22+
23+
#[cfg(not(feature = "std"))]
24+
impl<const S: usize> multihash::no_std_io::Write for $name<S> {
25+
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
26+
use multihash_derive::Hasher as _;
27+
28+
self.update(buf);
29+
Ok(buf.len())
30+
}
31+
}
2232
};
2333
}
2434

@@ -209,6 +219,16 @@ macro_rules! derive_rustcrypto_hasher {
209219
}
210220
}
211221

222+
#[cfg(not(feature = "std"))]
223+
impl multihash::no_std_io::Write for $name {
224+
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
225+
use multihash_derive::Hasher as _;
226+
227+
self.update(buf);
228+
Ok(buf.len())
229+
}
230+
}
231+
212232
impl ::digest::Update for $name {
213233
fn update(&mut self, data: &[u8]) {
214234
::multihash_derive::Hasher::update(self, data)

0 commit comments

Comments
 (0)