Add FuzzyEq trait ()

This commit is contained in:
Przemyslaw Hugh Kaznowski 2024-04-18 13:38:37 +01:00 committed by GitHub
parent 982e6b33fd
commit 0462d6a395
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

10
core/src/dbs/fuzzy_eq.rs Normal file
View file

@ -0,0 +1,10 @@
/// FuzzyEq trait is used to compare objects while ignoring values that are non-deterministic.
/// Non detereministic values include:
/// - Timestamps
/// - UUIDs
#[doc(hidden)]
pub trait FuzzyEq<Rhs: ?Sized = Self> {
/// Use this when comparing objects that you do not want to compare properties that are
/// non-deterministic
fn fuzzy_eq(&self, other: &Rhs) -> bool;
}

View file

@ -35,5 +35,7 @@ pub(crate) use self::statement::*;
pub(crate) use self::transaction::*;
pub(crate) use self::variables::*;
#[doc(hidden)]
pub mod fuzzy_eq;
#[cfg(test)]
pub(crate) mod test;

View file

@ -1,3 +1,5 @@
#[cfg(test)]
use crate::dbs::fuzzy_eq::FuzzyEq;
use crate::sql::{Object, Uuid, Value};
use revision::revisioned;
use serde::{Deserialize, Serialize};
@ -57,3 +59,10 @@ impl Notification {
}
}
}
#[cfg(test)]
impl FuzzyEq for Notification {
fn fuzzy_eq(&self, other: &Self) -> bool {
self.action == other.action && self.result == other.result
}
}