You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Awesome work here! Reviewing the documentation, I don't see an immediately obvious option for being able to specify that a field may be one of a set of types. In Rust this would typically look like:
enumVariants{ObjA(ObjA),ObjB(ObjB),}
I see that enums can be used for a known collection of ordered strings, and I see that there is also the any type. Would the idea be to use a combination of those items within a struct?
The text was updated successfully, but these errors were encountered:
There is no tagged union type in the library yet and I wouldn't recommend using the any type. The any type is really an escape hatch if you absolutely need untyped data.
I'm actually working on a union type right now, should have it deployed within a week or so.
I'm just trying to figure how to make the api as simple and usable as possible.
Getting the default property to work in a common sense way is proving to be a challenge, Union types might not have a default property when I finalize the feature. (But I'm really hoping I can make it work!)
And the API is going to be something like this:
// assuming the schema abovelet buffer = factory.new_buffer(None);
buffer.set(&["variant_1"],"testing");
assert_eq!(buffer.get(&["variant_1"], Some("testing"));
assert_eq!(buffer.get(&["variant_2"], None);
assert_eq!(buffer.get(&["variant_3"], None);
// discover what value the union currently haslet unionVal: NP_Union = buffer.get(&[]);
assert_eq!(unionVal, NP_Union::Value("variant_1"));
There are other complicated matters as well, like nesting unions that need to be figured out.
Awesome work here! Reviewing the documentation, I don't see an immediately obvious option for being able to specify that a field may be one of a set of types. In Rust this would typically look like:
I see that
enum
s can be used for a known collection of ordered strings, and I see that there is also theany
type. Would the idea be to use a combination of those items within a struct?The text was updated successfully, but these errors were encountered: