Enum shadow_rs::core::configuration::NullableOption
source · 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
runahead
option used in yaml) - null:
runahead: null
For clap, there are only two states:
- set:
--runahead 5ms
- not set: (no
--runahead
option 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
runahead
option 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
--runahead
option 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> JsonSchema for NullableOption<T>
impl<T: JsonSchema> JsonSchema for NullableOption<T>
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> 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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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<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