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

Should this work? #4

Closed
smoelius opened this issue Dec 24, 2021 · 4 comments
Closed

Should this work? #4

smoelius opened this issue Dec 24, 2021 · 4 comments

Comments

@smoelius
Copy link

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
enum Foo {
    A(String),
}

fn main() {
    let foo = Foo::A(String::new());

    let mut data = Vec::new();
    cbor4ii::serde::to_writer(&mut data, &foo).unwrap();

    let reader = std::io::BufReader::new(data.as_slice());
    let _: Foo = cbor4ii::serde::from_reader(reader).unwrap();
}

I get:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: RequireBorrowed { name: "str" }', src/main.rs:15:54

Can you tell me what am I doing wrong?

@quininer
Copy link
Owner

Oh, the deserialize_str behavior of serde is a bit hard to understand. I will fix it immediately.

@quininer
Copy link
Owner

Oh, the deserialize_str behavior of serde is a bit hard to understand. I will fix it immediately.

@smoelius
Copy link
Author

Thanks for the prompt reply.

@quininer
Copy link
Owner

I think this is like a bug in serde handling of enum, because the String type should obviously call deserialize_string to benefit from the owned type. but this is not a strong agreement, so cbor4ii should not rely on it.

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