Closed adamnemecek closed 1 year ago
That's a quirk of Rust. String::from(my_string)
and my_string.to_string()
are not the same.
I implemented Display
(presumably intended for display to end-users, terminal output) for these types. In Rust, the to_string()
function uses the Display
implementation to convert the enumeration into a string.
Therefore I'd argue that x.to_string()
is for rendering to display, log files, and such - and that String::from(x)
is better suited for internal processing, serialization, deserialization, etc.
I've implemented String::from
for these types. This will give the "code" (rather than the text) you're looking for. I haven't tried this myself, but you could try using String::from(&PlaceType::Accounting)
rather than serde_json::to_string(&PlaceType::Accounting).unwrap()
Just a note that I came around on this issue and this has been fixed.
This code does not work.