config-rs: Unable to deserialize unsigned integers
When implementing config::ValueKind
for a custom type, the error invalid type: unsigned integer 64 bit '128', expected an signed 64 bit or less integer for key 'inner.unsigned'
is thrown if the custom type contains a unsigned integer. The following is a minimum example:
#[derive(Deserialize, Eq, PartialEq, Debug)]
struct Container<T> {
inner: T,
}
#[derive(Deserialize, Eq, PartialEq, Debug)]
struct Unsigned {
unsigned: u16,
}
impl Default for Unsigned {
fn default() -> Self {
Self { unsigned: 128 }
}
}
impl From<Unsigned> for config::ValueKind {
fn from(unsigned: Unsigned) -> Self {
let mut properties = HashMap::default();
properties.insert(
"unsigned".to_string(),
config::Value::from(unsigned.unsigned),
);
Self::Table(properties)
}
}
assert_eq!(
Container {
inner: Unsigned::default()
},
config::Config::builder()
.set_default("inner", Unsigned::default())
.unwrap()
.build()
.unwrap()
.try_deserialize::<Container<Unsigned>>()
.unwrap()
);
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17
0.13.2 was just released. I’m closing this issue for now, feel free to open a new one if need be.
That is because a
Table
is constructed using anIndexMap
instead of aHashMap
if thepreserve_order
feature is enabled.