Stream: general

Topic: How to serialize BTreeMap

Daniel Papp (Jun 17 2019 at 12:04, on Zulip):

I have a BTreeMap<u64, CustomType> dict as a non-public member of a struct. serde::Serialize is already derived for CustomType. The question is how do I derive Serialize for BTreeMap<u64,CustomType> without deriving it for the whole class?

Jake Goulding (Jun 17 2019 at 13:29, on Zulip):

@Daniel Papp that doesn't really make sense. Serialize is implemented for BTreeMap by Serde itself. You can't implement a trait you don't own for a type you don't own (How do I implement a trait I don't own for a type I don't own?)

Jake Goulding (Jun 17 2019 at 13:30, on Zulip):

i think you need to provide more detail about your goals and what you have now

Daniel Papp (Jun 17 2019 at 13:57, on Zulip):

I see. I figured it out in the meantime. I mean that I can only define a trait implementation at the crate either where the trait or the type that I want to implement it for reside.

Last update: Jun 04 2020 at 18:40UTC