arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
miden-crypto/src/utils/diff.rs
src/utils/diff.rsRaw
 1/// A trait for computing the difference between two objects.
 2pub trait Diff<K: Ord + Clone, V: Clone> {
 3    /// The type that describes the difference between two objects.
 4    type DiffType;
 5
 6    /// Returns a [Self::DiffType] object that represents the difference between this object and
 7    /// other.
 8    fn diff(&self, other: &Self) -> Self::DiffType;
 9}
10
11/// A trait for applying the difference between two objects.
12pub trait ApplyDiff<K: Ord + Clone, V: Clone> {
13    /// The type that describes the difference between two objects.
14    type DiffType;
15
16    /// Applies the provided changes described by [Self::DiffType] to the object implementing this trait.
17    fn apply(&mut self, diff: Self::DiffType);
18}
19
20/// A trait for applying the difference between two objects with the possibility of failure.
21pub trait TryApplyDiff<K: Ord + Clone, V: Clone> {
22    /// The type that describes the difference between two objects.
23    type DiffType;
24
25    /// An error type that can be returned if the changes cannot be applied.
26    type Error;
27
28    /// Applies the provided changes described by [Self::DiffType] to the object implementing this trait.
29    /// Returns an error if the changes cannot be applied.
30    fn try_apply(&mut self, diff: Self::DiffType) -> Result<(), Self::Error>;
31}