Empty Type
The [EmptyType] trait and [Container] trait work together
to create structures with optional members and provides an api
convert between the two.
use ;
const JSON: &str = r#"{ "key": "value", "mismatch": "not a number" }"#;
The proc macro creates code roughly equivalent to the following
use ;
// This allows conversion between the two types
Proc Macro
The behavior above is tedious and complicated. The proc_macro [EmptyType] creates
the optional data structures for you with the feature derive enabled
Serde
Serde support is provided by the feature flag serde and a helper function [deserialize_empty]
is provided to deserialize empty values
# use ;
# use Deserialize;
const JSON: &str = r#" { "value": "data" } "#;
#
Container
Container is automatically implemented for [Option<T>] and bool. This allows
container unwraps to propagate up through containers.
Fallible
A special container types [Fallible] and [Optional] provide small variations to
the way that types are opened.
Optional
Optional is a wrapper around source types that are initially option. Optional
roughly represents Some(Option<T>). Opening this container always results in an [Option]
This is distinct from Option<Option<T>> as it's impossible for the wrapping option
to be None with the semantics described.
use Optional;
Fallible
Fallible is similar to Optional except it requires that the underlying type implement [Default].
The semantics of fallible are to always return the default value of the underlying [Container].
Another important distinction is that Fallible will swallow serde Deserialize errors. Any error in deserialization will result in the default type being emitted.
_