-
-
Notifications
You must be signed in to change notification settings - Fork 235
Open
Description
What version of the csv crate are you using?
1.3.0
Briefly describe the question, bug or feature request.
When deserializing to a String field using serde, csv can handle a field containing 123.
However, when doing the same to a flattened field, csv can no longer deserialize 123 to the String field and I get the error:
Err(
Error(
Deserialize {
pos: Some(
Position {
byte: 24,
line: 4,
record: 3,
},
),
err: DeserializeError {
field: None,
kind: Message(
"invalid type: integer `123`, expected a string",
),
},
},
),
)
Include a complete program demonstrating a problem.
use serde::Deserialize;
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
struct Inner {
inner_str: String,
}
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
struct Row {
str: String,
#[serde(flatten)]
inner: Inner,
}
fn main() {
let source = r#"
str,inner_str
A,A
123,A
A,123
"#
.trim();
let mut reader = csv::Reader::from_reader(source.as_bytes());
for line in reader.deserialize::<Row>() {
dbg!(&line);
}
}What is the observed behavior of the code above?
Output:
[src/main.rs:29] &line = Ok(
Row {
str: "A",
inner: Inner {
inner_str: "A",
},
},
)
[src/main.rs:29] &line = Ok(
Row {
str: "123",
inner: Inner {
inner_str: "A",
},
},
)
[src/main.rs:29] &line = Err(
Error(
Deserialize {
pos: Some(
Position {
byte: 24,
line: 4,
record: 3,
},
),
err: DeserializeError {
field: None,
kind: Message(
"invalid type: integer `123`, expected a string",
),
},
},
),
)
What is the expected or desired behavior of the code above?
Output:
[src/main.rs:29] &line = Ok(
Row {
str: "A",
inner: Inner {
inner_str: "A",
},
},
)
[src/main.rs:29] &line = Ok(
Row {
str: "123",
inner: Inner {
inner_str: "A",
},
},
)
[src/main.rs:29] &line = Ok(
Row {
str: "A",
inner: Inner {
inner_str: "123",
},
},
)
Dzordzu, hydra and vultix
Metadata
Metadata
Assignees
Labels
No labels