serde-hex icon indicating copy to clipboard operation
serde-hex copied to clipboard

Add support for deserialization of owned values

Open thomaseizinger opened this issue 4 years ago • 3 comments

Resolves #7.

There is some duplication between the visitors so there is potential for follow-up work. The feature works however and is tested with 2 additional tests I added.

Let me know what you think!

thomaseizinger avatar Apr 01 '20 07:04 thomaseizinger

Many thanks for this patch!

I have spend a lot of time trying to figure out why this toy example:

use serde::{Deserialize};
use serde_hex::{SerHex, CompactPfx};

#[derive(Debug, Deserialize)]
struct Foo {
    #[serde(with = "SerHex::<CompactPfx>")]
    bar: u32
}

const INI: &str = r#"bar = 0x42"#;

fn main() {
    let foo: Foo = serde_ini::from_str(INI).unwrap();
    println!("{:?}", foo);
}

Was providing the following result:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom("invalid type: string \"0x42\", expected a borrowed byte array")', src/main.rs:17:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Cheers!

gagath avatar Jul 24 '20 20:07 gagath

Awesome! Exactly what i needed! @fspmarshall Any chance to merge this soon?

nklhtv avatar Sep 13 '22 15:09 nklhtv

ping @fspmarshall

elpiel avatar Oct 11 '23 07:10 elpiel