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 the eventual value from an external source.
Explicitly set the value.
Implementations
impl<T> Override<T>
[src]
impl<T> Override<T>
[src]pub fn as_ref<'a>(&'a self) -> Override<&'a T>
[src]
Converts from Override<T>
to Override<&T>
.
Produces a new Override
, containing a reference into the original, leaving the original in place.
pub fn as_mut<'a>(&'a mut self) -> Override<&'a mut T>
[src]
Converts from Override<T>
to Override<&mut T>
.
Produces a new Override
, containing a mutable reference into the original.
pub fn is_explicit(&self) -> bool
[src]
Returns true
if the override is an Explicit
value.
pub fn explicit(self) -> Option<T>
[src]
Converts from Override<T>
to Option<T>
.
pub fn unwrap_or(self, optb: T) -> T
[src]
Unwraps an override, yielding the content of an Explicit
. Otherwise, it returns optb
.
pub fn unwrap_or_else<F>(self, op: F) -> T where
F: FnOnce() -> T,
[src]
F: FnOnce() -> T,
Unwraps an override, yielding the content of an Explicit
. Otherwise, it calls op
.
impl<T: Default> Override<T>
[src]
impl<T: Default> Override<T>
[src]pub fn unwrap_or_default(self) -> T
[src]
Returns the contained value or the default value of T
.
Trait Implementations
impl<T: FromMeta> FromMeta for Override<T>
[src]
impl<T: FromMeta> FromMeta for Override<T>
[src]Parses a Meta
. A bare word will produce Override::Inherit
, while
any value will be forwarded to T::from_meta
.
fn from_word() -> Result<Self>
[src]
fn from_list(items: &[NestedMeta]) -> Result<Self>
[src]
fn from_value(lit: &Lit) -> Result<Self>
[src]
fn from_nested_meta(item: &NestedMeta) -> Result<Self>
[src]
fn from_meta(item: &Meta) -> Result<Self>
[src]
fn from_char(value: char) -> Result<Self>
[src]
fn from_string(value: &str) -> Result<Self>
[src]
fn from_bool(value: bool) -> Result<Self>
[src]
impl<T: Eq> Eq for Override<T>
[src]
impl<T> StructuralEq for Override<T>
[src]
impl<T> StructuralPartialEq for Override<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Override<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Override<T> where
T: Send,
T: Send,
impl<T> Sync for Override<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Override<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Override<T> where
T: UnwindSafe,
T: UnwindSafe,