Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ path = "src/lib.rs"
[features]
default = ["impl_num"]
impl_num = ["num"]
impl_uuid = ["uuid"]

[dependencies]
diff_derive = "0.2.3"
serde = { version = "1", features = ["derive"] }
num = { version = "0.4.0", optional = true }
uuid = { version = "1.10.0", optional = true}

[dev-dependencies]
quickcheck = "0.8"
Expand Down
22 changes: 21 additions & 1 deletion src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;

#[cfg(feature = "uuid")]
impl Diff for uuid::Uuid {
type Repr = Option<uuid::Uuid>;
fn diff(&self, other: &Self) -> Self::Repr {
if self.as_u128().eq(&other.as_u128()) {
None
} else {
Some(*other)
}
}
fn apply(&mut self, diff: &Self::Repr) {
if let Some(diff) = diff {
*self = *diff;
}
}
fn identity() -> Self {
uuid::Uuid::from_u128(0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128)
}
}

impl Diff for bool {
type Repr = Option<bool>;

Expand Down Expand Up @@ -70,7 +90,7 @@ where
}

fn apply(&mut self, diff: &Self::Repr) {
self.as_mut().apply(diff.as_ref())
self.as_mut().apply(diff.as_ref())
}

fn identity() -> Self {
Expand Down