dtolnay / erased-serde

Type-erased Serialize, Serializer and Deserializer traits
Apache License 2.0
709 stars 36 forks source link

Deserialize / DeserializeOwned ? #59

Closed dakom closed 2 years ago

dakom commented 2 years ago

Use case is I have something like this:

async fn foo<A: Serialize, B: DeserializeOwned>(args:A) -> B { ... }

and I want to store it as a callback to be called later, i.e. something that looks like:

struct Callbacks {
    pub foo: Box<dyn Fn(Box<dyn erased_serde::Serialize>) -> Pin<Box<dyn Future<Output=Box<dyn erased_serde::DeserializeOwned>>>>>
}

However, erased_serde doesn't have DeserializeOwned.

Is it possible to add this?

I also brought this up in the Rust forum, in case the surrounding context is helpful in some way: https://users.rust-lang.org/t/how-to-store-callbacks-with-generics/78063/12?u=dakom

dtolnay commented 2 years ago

Looks like this got addressed in depth in the forum thread.

tqwewe commented 2 years ago

There's a lot to read through in the forum, is the sumarry that it's not possible?