Skip to content

Commit bd28515

Browse files
committed
feat: Add a feature to disable map support
The `map` feature, enabled by default, can be disable to remove map support, for codebases not supporting diffs over map to be expressed. See redbadger/pathogen#1 for some context on when map support might not be present.
1 parent 7d616b8 commit bd28515

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ thiserror = "1.0"
2828
uuid = { version = "1.11", optional = true }
2929

3030
[features]
31+
default = ["map"]
32+
33+
# impl Diffable on `std::collections::BTreeMap` and `std::collections::HashMap`
34+
map = []
35+
3136
# impl Diffable on `chrono::DateTime`
3237
chrono = ["dep:chrono"]
3338

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#![doc = include_str!("../README.md")]
22

3+
use std::{marker::PhantomData, ops::Deref};
4+
5+
#[cfg(feature = "map")]
36
use std::{
47
collections::{BTreeMap, HashMap},
58
hash::Hash,
6-
marker::PhantomData,
7-
ops::Deref,
89
};
910

1011
pub use difficient_macros::Diffable;
@@ -234,6 +235,7 @@ where
234235

235236
#[derive(Debug, Clone, PartialEq)]
236237
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
238+
#[cfg(feature = "map")]
237239
/// A generic type which represents the possible change-states of a Key-Value type
238240
/// (e.g. `HashMap`, `BTreeMap`)
239241
pub enum KvDiff<'a, T, U> {
@@ -270,6 +272,7 @@ impl_diffable_for_primitives! {
270272
String
271273
}
272274

275+
#[cfg(feature = "map")]
273276
macro_rules! kv_map_impl {
274277
($typ: ident, $bounds: ident) => {
275278
#[allow(
@@ -357,7 +360,10 @@ macro_rules! kv_map_impl {
357360
};
358361
}
359362

363+
#[cfg(feature = "map")]
360364
kv_map_impl!(HashMap, Hash);
365+
366+
#[cfg(feature = "map")]
361367
kv_map_impl!(BTreeMap, Ord);
362368

363369
impl Diffable<'_> for () {

src/serde_visit.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::{
44
hash::Hash,
55
};
66

7-
use super::{AtomicDiff, DeepDiff, Id, KvDiff, Replace};
7+
use super::{AtomicDiff, DeepDiff, Id, Replace};
8+
#[cfg(feature = "map")]
9+
use super::KvDiff;
810
use crate::PatchOnlyDiff;
911

1012
/// A trait that allows the user to extract information from a 'diff' type.
@@ -160,6 +162,7 @@ tuple_impl!(A 0, B 1, C 2);
160162
tuple_impl!(A 0, B 1);
161163
tuple_impl!(A 0);
162164

165+
#[cfg(feature = "map")]
163166
macro_rules! kv_map_impl {
164167
($typ: ident, $bounds: ident) => {
165168
#[allow(
@@ -196,7 +199,9 @@ macro_rules! kv_map_impl {
196199
};
197200
}
198201

202+
#[cfg(feature = "map")]
199203
kv_map_impl!(HashMap, Hash);
204+
#[cfg(feature = "map")]
200205
kv_map_impl!(BTreeMap, Ord);
201206

202207
#[cfg(test)]

0 commit comments

Comments
 (0)