actually set set enum variant when deserializing
This commit is contained in:
parent
3f9599e01b
commit
abb2170186
@ -647,7 +647,7 @@ impl Enum {
|
|||||||
D: ::serde::Deserializer<'de>,
|
D: ::serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let ::core::result::Result::Ok(key) = keys.next::<Self>() else {
|
let ::core::result::Result::Ok(key) = keys.next::<Self>() else {
|
||||||
<Self as ::serde::Deserialize>::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
|
*self = <Self as ::serde::Deserialize>::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
|
||||||
return ::core::result::Result::Ok(0);
|
return ::core::result::Result::Ok(0);
|
||||||
};
|
};
|
||||||
let index = ::miniconf::Key::find::<Self>(&key).ok_or(::miniconf::Traversal::NotFound(1))?;
|
let index = ::miniconf::Key::find::<Self>(&key).ok_or(::miniconf::Traversal::NotFound(1))?;
|
||||||
@ -656,7 +656,7 @@ impl Enum {
|
|||||||
}
|
}
|
||||||
match index {
|
match index {
|
||||||
0 => {
|
0 => {
|
||||||
<Self as ::serde::Deserialize>::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
|
*self = <Self as ::serde::Deserialize>::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
1..=#num_keys => ::core::result::Result::Err(::miniconf::Traversal::Access(0, "Cannot write limits").into()),
|
1..=#num_keys => ::core::result::Result::Err(::miniconf::Traversal::Access(0, "Cannot write limits").into()),
|
||||||
|
@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
|
|
||||||
/// Description
|
/// Description
|
||||||
#[derive(Default, ConfigEnum, Serialize, Deserialize)]
|
#[derive(Debug, Default, PartialEq, Eq, ConfigEnum, Serialize, Deserialize)]
|
||||||
enum Test {
|
enum Test {
|
||||||
#[default]
|
#[default]
|
||||||
Variant1,
|
Variant1,
|
||||||
@ -56,4 +56,7 @@ fn deserialize(
|
|||||||
|
|
||||||
let res = config.set_json(path, b"\"Variant3\"");
|
let res = config.set_json(path, b"\"Variant3\"");
|
||||||
assert_eq!(res, expected);
|
assert_eq!(res, expected);
|
||||||
|
if res.is_ok() {
|
||||||
|
assert_eq!(config, Test::Variant3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user