pub enum TriState<T> {
    Unset,
    Disabled,
    Set(T),
}
Expand description

Utility for tracking set vs. unset vs explicitly disabled

If someone explicitly disables something, we don’t need to warn them that it may be missing. This enum impls From/Into Option<T> for ease of use.

Variants

Unset

This variant represents something that was unset by default

Disabled

This variant represents something that was intentionally unset

Set(T)

This variant represents something that was intentionally set

Implementations

Create a TriState, returning Unset when None is passed

Return true if this TriState is Unset

Returns the tristate if it contains a set value or is disabled, otherwise returns other

Examples
let disabled_timeout: TriState<Duration> = TriState::Disabled;
let timeout: TriState<Duration> = TriState::Set(Duration::from_secs(1));
assert_eq!(timeout.or(disabled_timeout), TriState::Set(Duration::from_secs(1)));

let disabled_timeout: TriState<Duration> = TriState::Disabled;
let timeout: TriState<Duration> = TriState::Set(Duration::from_secs(2));
assert_eq!(disabled_timeout.or(timeout), TriState::Disabled);

let unset_timeout: TriState<Duration> = TriState::Unset;
let timeout: TriState<Duration> = TriState::Set(Duration::from_secs(3));
assert_eq!(unset_timeout.or(timeout), TriState::Set(Duration::from_secs(3)));

Maps a TriState<T> to TriState<U> by applying a function to a contained value.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.