Two options that I can think up:
Option 1: add a new property to the type_mappings entries:
type_mappings = [
"mojom.Foo = CustomFoo[nullable=same_type]",
"mojom.Bar = CustomBar[nullable=optional_wrapper]",
"mojom.Qux = CustomQux"
]
- By default a custom mapped type doesn't allow nullable.
- If |nullable=same_type| is specified, StructTraits::SetToNull() and IsNull() will be used to deal with null state.
- If |nullable=optional_wrapper| is specified, base::Optional<T> is used for nullable.
Option 2: use a separate entry for nullable:
type_mappings = [
"mojom.Foo = CustomFoo",
"mojom.Foo? = CustomFoo",
"mojom.Bar = CustomBar",
"mojom.Bar? = base::Optional<CustomBar>"
]
Pros (comparing with #1):
- It is more flexible, users can use whatever type they want for nullable.
Cons:
- It is more verbose.
- We want to treat base::Optional<> specially -- users don't have to write StructTraits for base::Optional<T> as long as there is a StructTriats<T> defined. #2 is a little less clear that it is treated specially.
I personally prefer #1 to #2. WDYT?
Thanks, Ken.
At the beginning I was thinking that "none" could be used to enforce that a type T is never marked as "nullable" in mojom files. Thinking about it some more, however, I feel that maybe it is not that useful. And it could be easily added later if needed.
WDYT? Thanks!
Comment 1 by yzshen@chromium.org
, Jul 6 2016