0

I am trying to serialize a struct using derive:

#[derive(Serialize)]
struct MyStruct {
    txt: ResolveResult<TxtLookup>
}

ResolveResult and TxtLookup are from trust-dns-resolver 0.20.3. I'm using serde 1.0 for the serialization.

I am getting the following error:

error[E0277]: the trait bound `TxtLookup: Serialize` is not satisfied
  --> src/main.rs:17:5
   |
17 |     txt: ResolveResult<TxtLookup>
   |     ^^^ the trait `Serialize` is not implemented for `TxtLookup`
   |
   = note: required because of the requirements on the impl of `Serialize` for `std::result::Result<TxtLookup, ResolveError>`
   = note: required by `_::_serde::ser::SerializeStruct::serialize_field`

error[E0277]: the trait bound `ResolveError: Serialize` is not satisfied
  --> src/main.rs:17:5
   |
17 |     txt: ResolveResult<TxtLookup>
   |     ^^^ the trait `Serialize` is not implemented for `ResolveError`
   |
   = note: required because of the requirements on the impl of `Serialize` for `std::result::Result<TxtLookup, ResolveError>`
   = note: required by `_::_serde::ser::SerializeStruct::serialize_field`

How do I implement serialization for TxtLookup and ResolveError? I am new to Rust so its difficult to comprehend.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Chirag Asarpota
  • 121
  • 1
  • 5
  • 1
    It looks like your question might be answered by the answers of [Serde serialize with proxy type for remote object](https://stackoverflow.com/q/61480342/155423); [Is there a way for me to use #[derive\] on a struct or enum from a library without editing the actual library's source code?](https://stackoverflow.com/q/48267016/155423). If not, please **[edit]** your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Dec 20 '21 at 20:09
  • 1
    Looks like that is what I was finding. thanks. @Shepmaster – Chirag Asarpota Dec 20 '21 at 20:21

0 Answers0