Support Enum
Closed this issue · 3 comments
Currently TreeObjectSpace
does not support Enum. As Enum is an integral part of Rust (e.g: Option
, Result
, etc), supporting for Enum is crucial.
This might require rethinking field name checking in Entry
as different subtypes in an enum may contain different field names. Refer https://serde.rs/json.html for more information on how enum is represented in serde-json
Currently there are two approaches:
- Remove the path validity checking code for all types. This is easy to achieve, yet make code for non-enum type less safe: we could refer to an invalid path without receiving an error.
- Check whether a type is an enum or not. How to achieve this is still unclear.
Current implementation of Entry
is unsuitable for supporting Enum. Currently an Entry
is in essence a map of path & path value to the collection of corresponding Arc<Value>
. This creates three problems:
- A lot of duplication of
Arc<Value>
causing "multiple source of truth" issue. - Different Enums serialized into differnt path. e.g:
enum MyEnum {
Str(String),
Person {name: String, age: i32}
}
serialized into either "Str": <string>
or "Person": {"name": <string>, "age": <int>}
3. Many functions however rely on the similarity of the Arc<Value>
collection of different path. For example, if different paths have different collections of Arc<Value>
, read_all
and take_all
will be very troublesome to implement as we have to get Value
from each path and then remove duplicates, which is inefficient.
A new approach is being explored in #7