Enum darling::util::Override [−][src]
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]
pub fn as_ref(&'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 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> Override<T> where
T: Default,
[src]
T: Default,
pub fn unwrap_or_default(self) -> T
[src]
Returns the contained value or the default value of T
.
Trait Implementations
impl<T> Clone for Override<T> where
T: Clone,
[src]
T: Clone,
impl<T> Debug for Override<T> where
T: Debug,
[src]
T: Debug,
impl<T> Default for Override<T>
[src]
impl<T> Display for Override<T> where
T: Display,
[src]
T: Display,
impl<T> Eq for Override<T> where
T: Eq,
[src]
T: Eq,
impl<T> From<Option<T>> for Override<T>
[src]
impl<T> FromMeta for Override<T> where
T: FromMeta,
[src]
T: FromMeta,
Parses a Meta
. A bare word will produce Override::Inherit
, while
any value will be forwarded to T::from_meta
.
pub fn from_word() -> Result<Override<T>, Error>
[src]
pub fn from_list(items: &[NestedMeta]) -> Result<Override<T>, Error>
[src]
pub fn from_value(lit: &Lit) -> Result<Override<T>, Error>
[src]
pub fn from_nested_meta(item: &NestedMeta) -> Result<Self, Error>
[src]
pub fn from_meta(item: &Meta) -> Result<Self, Error>
[src]
pub fn from_char(value: char) -> Result<Self, Error>
[src]
pub fn from_string(value: &str) -> Result<Self, Error>
[src]
pub fn from_bool(value: bool) -> Result<Self, Error>
[src]
impl<T> PartialEq<Override<T>> for Override<T> where
T: PartialEq<T>,
[src]
T: PartialEq<T>,
pub fn eq(&self, other: &Override<T>) -> bool
[src]
pub fn ne(&self, other: &Override<T>) -> bool
[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,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,