pub struct Overridable<T, const DEFAULT: isize = 500> { /* private fields */ }
Expand description
An overridable value based on priority.
This is a wrapper that provides the “magic” mechanism by which values can
be overridden across modules. After evaluating all modules, an Override<T>
will keep the value with the least priority.
If the priority of a value is not given, the default of 500 is assumed.
This can be changed by the DEFAULT
type parameter. If you need to change
this default, it is strongly recommended you make a type alias to avoid
specifying the default priority on each use.
§Example
let a = Overridable::with_priority("foo", 10);
let b = Overridable::with_priority("bar", 5);
let merged: Overridable<&str> = a.merge(b).unwrap();
assert_eq!(*merged, "bar");
§serde
This type deserializes as one of the following:
T
{ value: T }
{ value: T, priority: isize }
Implementations§
Source§impl<T, const DEFAULT: isize> Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> Overridable<T, DEFAULT>
Sourcepub fn with_priority<P>(value: T, priority: P) -> Self
pub fn with_priority<P>(value: T, priority: P) -> Self
Create a new value
with priority
.
Sourcepub fn set_priority<P>(&mut self, priority: P)
pub fn set_priority<P>(&mut self, priority: P)
Set the priority of this value.
Sourcepub fn into_value(self) -> T
pub fn into_value(self) -> T
Destruct this Overridable
and get the inner value.
Trait Implementations§
Source§impl<T, const DEFAULT: isize> AsMut<T> for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> AsMut<T> for Overridable<T, DEFAULT>
Source§impl<T, const DEFAULT: isize> AsRef<T> for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> AsRef<T> for Overridable<T, DEFAULT>
Source§impl<T, const DEFAULT: isize> Borrow<T> for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> Borrow<T> for Overridable<T, DEFAULT>
Source§impl<T, const DEFAULT: isize> BorrowMut<T> for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> BorrowMut<T> for Overridable<T, DEFAULT>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T: Clone, const DEFAULT: isize> Clone for Overridable<T, DEFAULT>
impl<T: Clone, const DEFAULT: isize> Clone for Overridable<T, DEFAULT>
Source§fn clone(&self) -> Overridable<T, DEFAULT>
fn clone(&self) -> Overridable<T, DEFAULT>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T, const DEFAULT: isize> Deref for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> Deref for Overridable<T, DEFAULT>
Source§impl<T, const DEFAULT: isize> DerefMut for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> DerefMut for Overridable<T, DEFAULT>
Source§impl<'de, T, const DEFAULT: isize> Deserialize<'de> for Overridable<T, DEFAULT>where
T: Deserialize<'de>,
Available on crate feature serde
only.
impl<'de, T, const DEFAULT: isize> Deserialize<'de> for Overridable<T, DEFAULT>where
T: Deserialize<'de>,
Available on crate feature
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T, const DEFAULT: isize> From<T> for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> From<T> for Overridable<T, DEFAULT>
Source§impl<T, const DEFAULT: isize> Merge for Overridable<T, DEFAULT>
impl<T, const DEFAULT: isize> Merge for Overridable<T, DEFAULT>
impl<T: Copy, const DEFAULT: isize> Copy for Overridable<T, DEFAULT>
Auto Trait Implementations§
impl<T, const DEFAULT: isize> Freeze for Overridable<T, DEFAULT>where
T: Freeze,
impl<T, const DEFAULT: isize> RefUnwindSafe for Overridable<T, DEFAULT>where
T: RefUnwindSafe,
impl<T, const DEFAULT: isize> Send for Overridable<T, DEFAULT>where
T: Send,
impl<T, const DEFAULT: isize> Sync for Overridable<T, DEFAULT>where
T: Sync,
impl<T, const DEFAULT: isize> Unpin for Overridable<T, DEFAULT>where
T: Unpin,
impl<T, const DEFAULT: isize> UnwindSafe for Overridable<T, DEFAULT>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more