exhaust/impls/
core_option.rs

1use crate::patterns::delegate_factory_and_iter;
2use crate::Exhaust;
3
4impl<T: Exhaust> Exhaust for Option<T> {
5    delegate_factory_and_iter!(remote::Option<T>);
6
7    fn from_factory(factory: Self::Factory) -> Self {
8        match remote::Option::from_factory(factory) {
9            remote::Option::None => None,
10            remote::Option::Some(v) => Some(v),
11        }
12    }
13}
14
15/// Like the Serde “remote derive” pattern, we define a type imitating the real type
16/// which the derive macro can process.
17mod remote {
18    #[allow(missing_debug_implementations)] // not actually public
19    #[derive(crate::Exhaust)]
20    pub enum Option<T> {
21        None,
22        Some(T),
23    }
24}