Enum darling_core::util::Override
[−]
[src]
pub enum Override<T> { Inherit, Explicit(T), }
A value which can inherit a default value or have an explicit value specified.
Usage
This type is meant for attributes like default
in darling
, which can take the following forms:
#[darling(default)]
#[darling(default="path::to::fn")]
In a struct collecting input for this attribute, that would be written as:
use darling::util::Override; #[derive(FromField)] #[darling(attributes(darling))] pub struct Options { default: Option<Override<syn::Path>>, } impl Options { fn hydrate(self) -> Option<syn::Path> { self.default.map(|ov| ov.unwrap_or(syn::parse_path("::Default::default").unwrap())) } }
The word
format (with no associated value), would produce Override::Inherit
, while a list
or value format would produce Override::Explicit
.
Variants
Inherit
Inherit the eventual value from an external source.
Explicit(T)
Explicitly set the value.
Methods
impl<T> Override<T>
[src]
fn as_ref<'a>(&'a self) -> Override<&'a T>
Converts from Override<T>
to Override<&T>
.
Produces a new Override
, containing a reference into the original, leaving the original in place.
fn as_mut<'a>(&'a mut self) -> Override<&'a T>
Converts from Override<T>
to Override<&mut T>
.
Produces a new Override
, containing a mutable reference into the original.
fn is_explicit(&self) -> bool
Returns true
if the override is an Explicit
value.
fn explicit(self) -> Option<T>
Converts from Override<T>
to Option<T>
.
fn unwrap_or(self, optb: T) -> T
Unwraps an override, yielding the content of an Explicit
. Otherwise, it returns optb
.
fn unwrap_or_else<F>(self, op: F) -> T where
F: FnOnce() -> T,
F: FnOnce() -> T,
Unwraps an override, yielding the content of an Explicit
. Otherwise, it calls op
.
impl<T: Default> Override<T>
[src]
fn unwrap_or_default(self) -> T
Returns the contained value or the default value of T
.
Trait Implementations
impl<T: Debug> Debug for Override<T>
[src]
impl<T: Clone> Clone for Override<T>
[src]
fn clone(&self) -> Override<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: PartialEq> PartialEq for Override<T>
[src]
fn eq(&self, __arg_0: &Override<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Override<T>) -> bool
This method tests for !=
.
impl<T: Eq> Eq for Override<T>
[src]
impl<T> Default for Override<T>
[src]
impl<T> From<Option<T>> for Override<T>
[src]
impl<T: Display> Display for Override<T>
[src]
impl<T: FromMetaItem> FromMetaItem for Override<T>
[src]
Parses a MetaItem
. A bare word will produce Override::Inherit
, while
any value will be forwarded to T::from_meta_item
.
fn from_word() -> Result<Self>
Create an instance from the presence of the word in the attribute with no additional options specified. Read more
fn from_list(items: &[NestedMetaItem]) -> Result<Self>
Create an instance from a list of nested meta items.
fn from_value(lit: &Lit) -> Result<Self>
Create an instance from a literal value of either foo = "bar"
or foo("bar")
. This dispatches to the appropriate method based on the type of literal encountered, and generally should not be overridden by implementers. Read more
fn from_nested_meta_item(item: &NestedMetaItem) -> Result<Self>
fn from_meta_item(item: &MetaItem) -> Result<Self>
Create an instance from a syn::MetaItem
by dispatching to the format-appropriate trait function. This generally should not be overridden by implementers. Read more
fn from_char(value: char) -> Result<Self>
Create an instance from a char literal in a value position.
fn from_string(value: &str) -> Result<Self>
Create an instance from a string literal in a value position.
fn from_bool(value: bool) -> Result<Self>
Create an instance from a bool literal in a value position.