Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for trait objects #10

Open
segeljakt opened this issue Apr 28, 2022 · 1 comment
Open

Support for trait objects #10

segeljakt opened this issue Apr 28, 2022 · 1 comment

Comments

@segeljakt
Copy link

segeljakt commented Apr 28, 2022

Hi again, I'm wondering, is it possible to use serde_state to serialize trait objects? I tried to use it together with serde_traitobject but it seems to require serde::Serialize. Is there some other way you know of to achieve this?

This is what serde_traitobject allows:

trait MyTrait: serde_traitobject::Serialize + serde_traitobject::Deserialize {
    fn my_method(&self);
}

#[derive(Serialize, Deserialize)]
struct Message {
    #[serde(with = "serde_traitobject")]
    message: Box<dyn MyTrait>,
}
@Marwes
Copy link
Owner

Marwes commented Apr 28, 2022

You would have to use serde_traitojbect (or the same approach at least). The only other option I know is to smuggle state via thread locals to let you use any non-state serializers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants