multiformats / rust-multihash

multihash implementation in Rust
https://github.com/multiformats/multihash
Other
150 stars 60 forks source link

regression serde feature does not work with no-std #336

Closed vmx closed 1 year ago

vmx commented 1 year ago

With the release of v0.19 we broke the ability to use Serde in no_std contexts. When you compile with:

$ cargo build --no-default-features --features serde
   Compiling multihash v0.19.0 (/tmp/rust-multihash)
error[E0432]: unresolved import `std`
 --> src/serde.rs:3:5
  |
3 | use std::fmt;
  |     ^^^ use of undeclared crate or module `std`

error: cannot find macro `format` in this scope
  --> src/serde.rs:35:46
   |
35 |             .map_err(|err| de::Error::custom(format!("Failed to deserialize Multihash: {}", err)))
   |                                              ^^^^^^

error: cannot find macro `format` in this scope
  --> src/serde.rs:48:46
   |
48 |             .map_err(|err| de::Error::custom(format!("Failed to deserialize Multihash: {}", err)))
   |                                              ^^^^^^

error[E0599]: no method named `to_bytes` found for reference `&Multihash<SIZE>` in the current scope
  --> src/serde.rs:17:42
   |
17 |         serializer.serialize_bytes(&self.to_bytes())
   |                                          ^^^^^^^^ method not found in `&Multihash<SIZE>`

error[E0433]: failed to resolve: use of undeclared type `Vec`
  --> src/serde.rs:43:25
   |
43 |         let mut bytes = Vec::new();
   |                         ^^^ use of undeclared type `Vec`

Some errors have detailed explanations: E0432, E0433, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `multihash` (lib) due to 5 previous errors

This is a regression as it works with v0.18.