Rust can't find serde::de::DeserializeOwned
in my code but can find serde::Serialize
. I'm pretty sure they both exist in serde 1.0.104 though:
#[derive(serde::Serialize, serde::de::DeserializeOwned, Default, Debug)]
struct Outside {}
Error:
error[E0433]: failed to resolve: could not find `DeserializeOwned` in `de`
--> src/lib.rs:3:39
|
1 | #[derive(serde::Serialize, serde::de::DeserializeOwned, Default, Debug)]
| ^^^^^^^^^^^^^^^^ could not find `DeserializeOwned` in `de`
Link to the playground
The automatic implementation of a trait is done through a procedural macro. If you go to the serde::Deserialize
documentation page, you'll see this sentence:
Additionally, Serde provides a procedural macro called
serde_derive
to automatically generateDeserialize
implementations for structs and enums in your program.
However, there is no procedural macro to implement the serde::de::DeserializeOwned
trait automatically, that's why your code cannot compile.
To know what you can do, you can read the serde documentation: it explains that DeserializeOwned
is a fancy way to use Deserialize
whatever the lifetime is. You just have to add #[derive(serde::Deserialize)]
and use the DeserializeOwned
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With