-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make twix user config keys optional (#1527)
- Loading branch information
Showing
3 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::collections::HashMap; | ||
use std::hash::Hash; | ||
|
||
pub trait Merge<T> { | ||
/// Merge `other` into `self`. | ||
/// `self` acts as a baseline, | ||
/// and items in `other` take precedence in the case of a conflict. | ||
fn merge(&mut self, other: T); | ||
} | ||
|
||
impl<K, V> Merge<Self> for HashMap<K, V> | ||
where | ||
K: Eq + Hash, | ||
{ | ||
fn merge(&mut self, other: Self) { | ||
self.extend(other); | ||
} | ||
} | ||
|
||
impl<T: Merge<T>> Merge<Option<T>> for T { | ||
fn merge(&mut self, other: Option<T>) { | ||
if let Some(value) = other { | ||
self.merge(value); | ||
} | ||
} | ||
} |