Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for diffus #55

Closed
wants to merge 2 commits into from
Closed
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
83 changes: 66 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/newtype-uuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ all-features = true
rustdoc-args = ["--cfg=doc_cfg"]

[dependencies]
diffus = { version = "0.10.0", optional = true, features = ["uuid-impl", "derive"] }
serde = { version = "1", optional = true, features = ["derive"] }
schemars = { version = "0.8", features = ["uuid1"], optional = true }
uuid = { version = "1.7.0", default-features = false }

[features]
default = ["uuid/default", "std"]
diffus = ["dep:diffus"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be diffus010 to match schemars08 below?

std = ["uuid/std", "alloc"]
alloc = []
v4 = ["uuid/v4"]
Expand Down
1 change: 1 addition & 0 deletions crates/newtype-uuid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ permits conversions between typed and untyped UUIDs.
## Features

- `default`: Enables default features in the newtype-uuid crate.
- `diffus`: Enables type diff support via [diffus](https://github.com/distil/diffus)
- `std`: Enables the use of the standard library. *Enabled by default.*
- `serde`: Enables serialization and deserialization support via Serde. *Not enabled by
default.*
Expand Down
24 changes: 24 additions & 0 deletions crates/newtype-uuid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
//! # Features
//!
//! - `default`: Enables default features in the newtype-uuid crate.
//! - `diffus`: Enables type diff support via [diffus](https://github.com/distil/diffus)
//! - `std`: Enables the use of the standard library. *Enabled by default.*
//! - `serde`: Enables serialization and deserialization support via Serde. *Not enabled by
//! default.*
Expand Down Expand Up @@ -367,6 +368,29 @@ mod schemars08_imp {
}
}

#[cfg(feature = "diffus")]
mod diffus_imp {
use super::*;
use diffus::{edit, Diffable};

/// Implements `Diffable` for `TypedUuid<T>`, if `T` implements `Diffable`.
impl<'a, T> Diffable<'a> for TypedUuid<T>
where
T: TypedUuidKind + Diffable<'a>,
{
type Diff = (&'a Self, &'a Self);

#[inline]
fn diff(&'a self, other: &'a Self) -> edit::Edit<'a, Self> {
if self.uuid == other.uuid {
edit::Edit::Copy(self)
} else {
edit::Edit::Change((self, other))
}
}
}
}

/// Represents marker types that can be used as a type parameter for [`TypedUuid`].
///
/// Generally, an implementation of this will be a zero-sized type that can never be constructed. An
Expand Down
2 changes: 1 addition & 1 deletion scripts/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -e -o pipefail

CARGO="${CARGO:-cargo}"
EXCLUDED_FEATURES_BY_DEFAULT=(internal-schemars08-tests)
EXCLUDED_FEATURES_NO_STD=(schemars08 serde default std alloc v4)
EXCLUDED_FEATURES_NO_STD=(schemars08 serde default std alloc v4 diffus)

trap 'echo_err "Error occurred at $0 command: $BASH_COMMAND"' ERR
trap 'echo_err "Exiting $0"' EXIT
Expand Down
Loading