quininer / cbor4ii

CBOR: Concise Binary Object Representation
MIT License
54 stars 5 forks source link

Should this work? #4

Closed smoelius closed 2 years ago

smoelius commented 2 years ago
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 commented 2 years ago

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

quininer commented 2 years ago

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

smoelius commented 2 years ago

Thanks for the prompt reply.

quininer commented 2 years ago

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.