did-key.rs
did-key.rs copied to clipboard
Example program doesn't compile; complains about `alloc` needing to be enabled
This trivial program doesn't compile:
use did_key::Fingerprint;
fn main() {
match did_key::resolve("did:key:z9Bg7Lbpq3RzgN8RkgEuZqLDF4nT1ZzobJe9ZPbS6HJpQ") {
Ok(k) => println!("{:?}", k.fingerprint()),
Err(e) => println!("{:?}", e),
}
}
The output is:
❯ cargo run
Compiling form_urlencoded v1.2.1
error: the `alloc` feature must currently be enabled
--> /home/harm/.cargo/registry/src/index.crates.io-6f17d22bba15001f/form_urlencoded-1.2.1/src/lib.rs:24:1
|
24 | compile_error!("the `alloc` feature must currently be enabled");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `Cow<'_, _>: From<PercentDecode<'_>>` is not satisfied
--> /home/harm/.cargo/registry/src/index.crates.io-6f17d22bba15001f/form_urlencoded-1.2.1/src/lib.rs:72:55
|
72 | decode_utf8_lossy(match percent_decode(&replaced).into() {
| ^^^^ the trait `From<PercentDecode<'_>>` is not implemented for `Cow<'_, _>`
|
= help: the following other types implement trait `From<T>`:
<Cow<'a, CStr> as From<CString>>
<Cow<'a, CStr> as From<&'a CStr>>
<Cow<'a, CStr> as From<&'a CString>>
<Cow<'a, str> as From<&'a str>>
<Cow<'a, str> as From<String>>
<Cow<'a, str> as From<&'a String>>
<Cow<'a, [T]> as From<&'a [T]>>
<Cow<'a, [T]> as From<Vec<T>>>
<Cow<'a, [T]> as From<&'a Vec<T>>>
= note: required for `PercentDecode<'_>` to implement `Into<Cow<'_, _>>`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `form_urlencoded` (lib) due to 2 previous errors
Adding the form_urlencoded crate explicitly fixes the error:
❯ cargo add form_urlencoded
Updating crates.io index
Adding form_urlencoded v1.2.1 to dependencies.
Features:
+ alloc
+ std
I doubt this is expected behaviour. Notably I was able to run the test of this repo without this issue and no mention of alloc was made anywhere.
Crate version 0.2.1.
Same thing here. For a simple example project with just did-key dependency, it does not compile. I get the same error as OP.
However, in a more complex project, it works. With some investigation, the complex project has another dependency that also depends on form_urlencoded with the alloc feature enabled, and given how cargo feature unioning works it makes sense that it works.