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

fix deserializing Option::Some #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jobafr
Copy link

@jobafr jobafr commented Sep 5, 2024

Hi,

there's a bug when Deserialize-ing a struct that contains an Option as one of its fields. We use this via rosrust to query a substructure of interrelated configuration parameters in a typed manner.

Example to reproduce:

use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Config {
    a : String,
    b : Option<i64>,
    sub : Option<SubStruct>
}

#[derive(Debug, Deserialize)]
struct SubStruct {
    c : Option<f32>
}

fn main() {
    rosrust::init("node");
    let config = rosrust::param("/config").unwrap().get::<Config>().unwrap();
    println!("{:#?}", config);
}

Load this YAML file as rosparams (rosparam load params.yaml):

config:
  a: "hello"
  sub:
    c: 3.1

Then cargo run it. With the current git main branch of xml-rpc-rs, we get

thread 'main' panicked at src/main.rs:17:69:
called `Result::unwrap()` on an `Err` value: Server("Response data has unexpected structure: Issue while decoding data structure: invalid value: map, expected option")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

With this patch, we get:

Config {
    a: "hello",
    b: None,
    sub: Some(
        SubStruct {
            c: Some(
                3.1,
            ),
        },
    ),
}

Note that Option now behaves as expected for the Some case as well as the None case (the latter did work already before).

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

Successfully merging this pull request may close these issues.

1 participant