Enum darling_core::util::Override  
source · [−]pub enum Override<T> {
    Inherit,
    Explicit(T),
}Expand description
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, FromField};
#[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.
Implementations
sourceimpl<T> Override<T>
 
impl<T> Override<T>
sourcepub fn as_ref(&self) -> Override<&T>
 
pub fn as_ref(&self) -> Override<&T>
Converts from Override<T> to Override<&T>.
Produces a new Override, containing a reference into the original, leaving the original in place.
sourcepub fn as_mut(&mut self) -> Override<&mut T>
 
pub fn as_mut(&mut self) -> Override<&mut T>
Converts from Override<T> to Override<&mut T>.
Produces a new Override, containing a mutable reference into the original.
sourcepub fn is_explicit(&self) -> bool
 
pub fn is_explicit(&self) -> bool
Returns true if the override is an Explicit value.
sourcepub fn unwrap_or(self, optb: T) -> T
 
pub fn unwrap_or(self, optb: T) -> T
Unwraps an override, yielding the content of an Explicit. Otherwise, it returns optb.
sourcepub fn unwrap_or_else<F>(self, op: F) -> T where
    F: FnOnce() -> T, 
 
pub fn unwrap_or_else<F>(self, op: F) -> T where
    F: FnOnce() -> T, 
Unwraps an override, yielding the content of an Explicit. Otherwise, it calls op.
sourceimpl<T: Default> Override<T>
 
impl<T: Default> Override<T>
sourcepub fn unwrap_or_default(self) -> T
 
pub fn unwrap_or_default(self) -> T
Returns the contained value or the default value of T.
Trait Implementations
sourceimpl<T: FromMeta> FromMeta for Override<T>
 
impl<T: FromMeta> FromMeta for Override<T>
Parses a Meta. A bare word will produce Override::Inherit, while
any value will be forwarded to T::from_meta.
sourcefn from_word() -> Result<Self>
 
fn from_word() -> Result<Self>
Create an instance from the presence of the word in the attribute with no additional options specified. Read more
sourcefn from_list(items: &[NestedMeta]) -> Result<Self>
 
fn from_list(items: &[NestedMeta]) -> Result<Self>
Create an instance from a list of nested meta items.
sourcefn from_value(lit: &Lit) -> Result<Self>
 
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: &NestedMeta) -> Result<Self>
sourcefn from_meta(item: &Meta) -> Result<Self>
 
fn from_meta(item: &Meta) -> Result<Self>
Create an instance from a syn::Meta by dispatching to the format-appropriate
trait function. This generally should not be overridden by implementers. Read more
sourcefn from_none() -> Option<Self>
 
fn from_none() -> Option<Self>
When a field is omitted from a parent meta-item, from_none is used to attempt
recovery before a missing field error is generated. Read more
sourcefn from_char(value: char) -> Result<Self>
 
fn from_char(value: char) -> Result<Self>
Create an instance from a char literal in a value position.
sourcefn from_string(value: &str) -> Result<Self>
 
fn from_string(value: &str) -> Result<Self>
Create an instance from a string literal in a value position.
impl<T: Eq> Eq for Override<T>
impl<T> StructuralEq for Override<T>
impl<T> StructuralPartialEq for Override<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Override<T> where
    T: RefUnwindSafe, 
impl<T> Send for Override<T> where
    T: Send, 
impl<T> Sync for Override<T> where
    T: Sync, 
impl<T> Unpin for Override<T> where
    T: Unpin, 
impl<T> UnwindSafe for Override<T> where
    T: UnwindSafe, 
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
    T: ?Sized, 
 
impl<T> BorrowMut<T> for T where
    T: ?Sized, 
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
 
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
    T: Clone, 
 
impl<T> ToOwned for T where
    T: Clone, 
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
 
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
 
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more