mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-15 02:41:01 +00:00
Allow Result<T, E> to use usize variant names
This commit is contained in:
@@ -877,6 +877,14 @@ impl<T, E> Deserialize for Result<T, E> where T: Deserialize, E: Deserialize {
|
|||||||
impl ::de::Visitor for FieldVisitor {
|
impl ::de::Visitor for FieldVisitor {
|
||||||
type Value = Field;
|
type Value = Field;
|
||||||
|
|
||||||
|
fn visit_usize<E>(&mut self, value: usize) -> Result<Field, E> where E: Error {
|
||||||
|
match value {
|
||||||
|
0 => Ok(Field::Ok),
|
||||||
|
1 => Ok(Field::Err),
|
||||||
|
_ => Err(Error::unknown_field_error(&value.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_str<E>(&mut self, value: &str) -> Result<Field, E> where E: Error {
|
fn visit_str<E>(&mut self, value: &str) -> Result<Field, E> where E: Error {
|
||||||
match value {
|
match value {
|
||||||
"Ok" => Ok(Field::Ok),
|
"Ok" => Ok(Field::Ok),
|
||||||
|
|||||||
Reference in New Issue
Block a user