Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<!-- next-header -->
## Unreleased - ReleaseDate

### Fixed

- `IndexMapDiff` and `IndexSetDiff` are now re-exported at the crate root, matching the other map and set diff types, and have rustdoc examples.

## [0.1.6] - 2026-05-14

### Added
Expand Down
2 changes: 2 additions & 0 deletions daft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,5 @@ pub use diffable::*;
pub use leaf::*;
#[cfg(feature = "std")]
pub use std_impls::*;
#[cfg(feature = "indexmap")]
pub use third_party::indexmap::*;
92 changes: 90 additions & 2 deletions daft/src/third_party/indexmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,96 @@ use crate::Diffable;
use core::hash::Hash;
use indexmap::{IndexMap, IndexSet};

map_diff!(IndexMap, Hash);
set_diff!(IndexSet, Hash);
map_diff!(
/// A diff of two [`IndexMap`] instances.
///
/// The diff contains three elements:
///
/// - `common`: Entries that are present in both maps, with their values
/// stored as a [`Leaf`][crate::Leaf].
/// - `added`: Entries present in `after`, but not in `before`.
/// - `removed`: Entries present in `before`, but not in `after`.
///
/// If `V` implements `Eq`, `common` can be split into
/// [`unchanged`][Self::unchanged] and [`modified`][Self::modified] entries.
/// Additionally, if `V` implements [`Diffable`],
/// [`modified_diff`][Self::modified_diff] can be used to recursively diff
/// modified entries.
///
/// [`IndexMap`]: indexmap::IndexMap
///
/// # Example
///
/// ```
/// # #[cfg(feature = "indexmap")] {
/// use daft::{Diffable, IndexMapDiff, Leaf};
/// use indexmap::IndexMap;
///
/// let a: IndexMap<usize, &str> =
/// [(0, "lorem"), (1, "ipsum"), (2, "dolor")].into_iter().collect();
/// let b: IndexMap<usize, &str> =
/// [(1, "ipsum"), (2, "sit"), (3, "amet")].into_iter().collect();
///
/// let changes = a.diff(&b);
/// let expected = IndexMapDiff {
/// // Keys are stored by reference and matched by equality.
/// common: [
/// (&1, Leaf { before: &"ipsum", after: &"ipsum" }),
/// (&2, Leaf { before: &"dolor", after: &"sit" }),
/// ].into_iter().collect(),
/// added: [(&3, &"amet")].into_iter().collect(),
/// removed: [(&0, &"lorem")].into_iter().collect(),
/// };
///
/// assert_eq!(changes, expected);
///
/// // If the values are `Eq`, it's also possible to get lists of
/// // modified and unchanged entries.
/// assert!(changes.is_unchanged(&1));
/// assert!(changes.is_modified(&2));
/// let unchanged = changes.unchanged().collect::<Vec<_>>();
/// let modified = changes.modified().collect::<Vec<_>>();
///
/// assert_eq!(unchanged, [(&1, &"ipsum")]);
/// assert_eq!(modified, [(&2, Leaf { before: &"dolor", after: &"sit" })]);
/// # }
/// ```
IndexMap, Hash
);
set_diff!(
/// A diff of two [`IndexSet`] instances.
///
/// The diff contains three elements:
///
/// - `common`: Entries that are present in both sets.
/// - `added`: Entries present in `after`, but not in `before`.
/// - `removed`: Entries present in `before`, but not in `after`.
///
/// [`IndexSet`]: indexmap::IndexSet
///
/// # Example
///
/// ```
/// # #[cfg(feature = "indexmap")] {
/// use daft::{Diffable, IndexSetDiff};
/// use indexmap::IndexSet;
///
/// let a: IndexSet<usize> = [0, 1].into_iter().collect();
/// let b: IndexSet<usize> = [1, 2].into_iter().collect();
///
/// let changes = a.diff(&b);
/// let expected = IndexSetDiff {
/// // Entries are stored by reference and matched by equality.
/// common: [&1].into_iter().collect(),
/// added: [&2].into_iter().collect(),
/// removed: [&0].into_iter().collect(),
/// };
///
/// assert_eq!(changes, expected);
/// # }
/// ```
IndexSet, Hash
);

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion daft/src/third_party/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementations for third-party libraries.

#[cfg(feature = "indexmap")]
mod indexmap;
pub(crate) mod indexmap;
#[cfg(feature = "newtype-uuid1")]
mod newtype_uuid_impls;
#[cfg(feature = "oxnet01")]
Expand Down
Loading