Closed emgrav closed 2 years ago
This error occurs in the from_yaml_value
function in the format/yaml.rs
specifically in the yaml::Yaml::Hash(ref table)
variant.
if let Some(k) = key.as_str() {
m.insert(k.to_owned(), from_yaml_value(uri, value)?);
}
Because the hash is nested it attempts to insert the keys
in the Map as &str
this conflicts with an integer key yaml::Yaml::Integer(k)
and so a quick fix to this could be.
match key{
yaml::Yaml::String(k) =>{
m.insert(k.to_owned(), from_yaml_value(uri, value)?);
}
yaml::Yaml::Integer(k) =>{
m.insert(k.to_string(), from_yaml_value(uri, value)?);
},
_ => unreachable!()
}
I have tested this and it seems to solve the problem, @matthiasbeyer if you are happy with this quick fix I will be happy to send a pull request if requested.
Yes, a patch would be nice.
Also: Does YAML allow other types as keys? For example floats? Would be the perfect opportunity to fix this as well :laughing: !
@matthiasbeyer I don't think so. It's evident from the yaml
parser that it only supports Integer(i64)
, I have also looked online but I couldn't find anything to suggest that.
Attempting to deserialize a map with an integer key fails, but does not produce an error. Putting quotes around the key makes it work as expected. This is using config
0.13.1
.Output: