pub enum NullableOption<T> {
    Value(T),
    Null,
}Expand description
This wrapper type allows cli options to specify “null” to overwrite a config file option with
None, and is intended to be used for options where “null” is a valid option value.
Warning: This may result in unexpected behaviour when wrapping string types. For example, if this is used for a file path option, the value “null” will conflict with the valid filename “null”. So if the user specifies “null” for this option, Shadow will assume it means “no value” rather than the filename “null”.
§Motivation
For configuration options, there are generally three states:
- set
 - not set
 - null
 
For serde, all three states are configurable:
- set: 
runahead: 5ms - not set: (no 
runaheadoption used in yaml) - null: 
runahead: null 
For clap, there are only two states:
- set: 
--runahead 5ms - not set: (no 
--runaheadoption used in command) 
There is no way to set a “null” state for cli options with clap.
§Configuration in Shadow
Shadow first parses the config file and cli options separately before merging them.
Parsing for serde:
- set: 
runahead: 5ms=> runahead is set toSome(5ms) - not set: (no 
runaheadoption used in yaml) => runahead is set to its default (eitherSome(..)orNone) - null: 
runahead: null=> runahead is set toNone 
Parsing for clap:
- set: 
--runahead 5ms=> runahead is set toSome(5ms) - not set: (no 
--runaheadoption used in command) => runahead is set toNone 
Then the options are merged such that any Some(..) options from the cli options will overwrite
any Some or None options from the config file.
The issue is that no clap option can overwrite a config file option of Some with a value of
None. For example if the config file specifies runahead: 5ms, then with clap you can only
use --runahead 2ms to change the runahead to a Some(2ms) value, or you can not set
--runahead at all to leave it as a Some(5ms) value. But there is no cli option to change the
runahead to a None value.
This NullableOption type is a wrapper to allow you to specify “null” on the command line to
overwrite the config file value with None. From the example above, you could now specify
“–runahead null” to overwrite the config file value (for example Some(5ms)) with a None
value.
Variants§
Implementations§
Source§impl<T> NullableOption<T>
 
impl<T> NullableOption<T>
Trait Implementations§
Source§impl<T: Clone> Clone for NullableOption<T>
 
impl<T: Clone> Clone for NullableOption<T>
Source§fn clone(&self) -> NullableOption<T>
 
fn clone(&self) -> NullableOption<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for NullableOption<T>
 
impl<T: Debug> Debug for NullableOption<T>
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for NullableOption<T>
 
impl<'de, T: Deserialize<'de>> Deserialize<'de> for NullableOption<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
 
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<T> FromStr for NullableOption<T>
 
impl<T> FromStr for NullableOption<T>
Source§impl<T> JsonSchema for NullableOption<T>where
    T: JsonSchema,
 
impl<T> JsonSchema for NullableOption<T>where
    T: JsonSchema,
Source§fn schema_id() -> Cow<'static, str>
 
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
 
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
 
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl<T: PartialEq> PartialEq for NullableOption<T>
 
impl<T: PartialEq> PartialEq for NullableOption<T>
Source§impl<T: Serialize> Serialize for NullableOption<T>
 
impl<T: Serialize> Serialize for NullableOption<T>
impl<T: Copy> Copy for NullableOption<T>
impl<T: Eq> Eq for NullableOption<T>
impl<T> StructuralPartialEq for NullableOption<T>
Auto Trait Implementations§
impl<T> Freeze for NullableOption<T>where
    T: Freeze,
impl<T> RefUnwindSafe for NullableOption<T>where
    T: RefUnwindSafe,
impl<T> Send for NullableOption<T>where
    T: Send,
impl<T> Sync for NullableOption<T>where
    T: Sync,
impl<T> Unpin for NullableOption<T>where
    T: Unpin,
impl<T> UnwindSafe for NullableOption<T>where
    T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
 
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more