message: ValueDiff: Add helper functions to apply an update
diff: @@ -36,6 +36,32 @@ pub enum ValueDiff<T> {
  Replace(T, T),
  }
  +impl<T> ValueDiff<T> where T: Eq {
  +
  + pub fn check(&self, dest: &T) -> bool {
  + match &self {
  + ValueDiff::None => true,
  + ValueDiff::Replace(old, _) => dest == old
  + }
  + }
  +
  + /// Apply this diff to a destination, overwriting it with the new
  + /// value if it is equal to the expected old value. Panic if the
  + /// old value is unexpected. (The caller is expected to use
  + /// `check` first to validate the expected state of all values in
  + /// an update first. We panic to ensure that we don't end up in a
  + /// half-update state.)
  + pub fn apply_to(self, dest: &mut T) {
  + match self {
  + ValueDiff::None => {}
  + ValueDiff::Replace(old, new) => {
  + assert!(dest == &old);
  + *dest = new;
  + }
  + }
  + }
  +}
  +
  #[derive(Debug, PartialEq, Eq, Clone)]
  pub struct SettingsDiff {
  pub block_id: ValueDiff<Hash>,
  