Skip to content

Commit af34499

Browse files
authored
Merge pull request #15 from Pscheidl/debug-eq-features
feat: Debug and Eq implementations feature-flagged, enabled by default
2 parents 1d6f673 + c0f4743 commit af34499

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Enum Collections for Rust
22
[![Rust](https://github.com/Pscheidl/enum-map/actions/workflows/rust.yml/badge.svg)](https://github.com/Pscheidl/enum-map/actions/workflows/rust.yml)
33
[![Crates.io](https://img.shields.io/crates/v/enum-collections)](https://crates.io/crates/enum-collections)
4+
[![docs.rs](https://img.shields.io/docsrs/enum-collections)](https://docs.rs/enum-collections/latest/enum_collections/)
45

56
[Contribution guide](CONTRIBUTING.md) | [Apache v2 license](LICENSE)
67

@@ -71,6 +72,12 @@ Using Index and IndexMut syntactic sugar.
7172
assert_eq!(u8::default(), map[Letter::B]);
7273
```
7374

75+
## Features
76+
77+
Portions of functionality are feature-flagged, but enabled by default. This is to allow turning this functionality off when not needed, e.g. `Debug` and `Eq` implementations.
78+
79+
See [docs.rs](https://docs.rs/crate/enum-collections/latest/features) for details.
80+
7481
## Benchmarks
7582

7683
There are single-threaded benchmarks for the `get`, `insert` and `remove` operations in [enum-collections/benches](enum-collections/benches/). Invoke `cargo bench` to run them.

enum-collections/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ keywords = ["collections", "hashmap", "hashtable", "enum", "enummap"]
1212
categories = ["data-structures"]
1313
documentation = "https://docs.rs/enum-collections"
1414

15+
[features]
16+
default = ["debug", "eq"]
17+
debug = []
18+
eq = []
19+
1520
[dependencies]
1621
enum-collections-macros = { path = "../enum-collections-macros", version = "0.3.0" }
1722

enum-collections/src/enummap.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ where
123123
}
124124
}
125125

126+
#[cfg(feature = "debug")]
126127
impl<K, V> Debug for EnumMap<K, V>
127128
where
128129
K: Enumerated + Debug,
@@ -141,6 +142,7 @@ where
141142
}
142143
}
143144

145+
#[cfg(feature = "eq")]
144146
impl<K, V> PartialEq<Self> for EnumMap<K, V>
145147
where
146148
K: Enumerated,
@@ -151,6 +153,7 @@ where
151153
}
152154
}
153155

156+
#[cfg(feature = "eq")]
154157
impl<K, V> Eq for EnumMap<K, V>
155158
where
156159
K: Enumerated,
@@ -204,7 +207,7 @@ mod tests {
204207
A,
205208
B,
206209
}
207-
210+
#[cfg(feature = "debug")]
208211
#[test]
209212
fn debug() {
210213
let mut enum_map = EnumMap::<LetterDebugDerived, i32>::new();
@@ -214,6 +217,7 @@ mod tests {
214217
assert_eq!(expected_output, debug_output);
215218
}
216219

220+
#[cfg(feature = "eq")]
217221
#[test]
218222
fn eq() {
219223
let mut first_map = EnumMap::<LetterDebugDerived, i32>::new();

enum-collections/src/enumtable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ where
106106
}
107107
}
108108

109+
#[cfg(feature = "debug")]
109110
impl<K, V> Debug for EnumTable<K, V>
110111
where
111112
K: Enumerated + Debug,
@@ -124,6 +125,7 @@ where
124125
}
125126
}
126127

128+
#[cfg(feature = "eq")]
127129
impl<K, V> PartialEq<Self> for EnumTable<K, V>
128130
where
129131
K: Enumerated,
@@ -134,6 +136,7 @@ where
134136
}
135137
}
136138

139+
#[cfg(feature = "eq")]
137140
impl<K, V> Eq for EnumTable<K, V>
138141
where
139142
K: Enumerated,
@@ -198,6 +201,7 @@ mod tests {
198201
B,
199202
}
200203

204+
#[cfg(feature = "debug")]
201205
#[test]
202206
fn debug() {
203207
let mut enum_table = EnumTable::<LetterDebugDerived, i32>::new();
@@ -207,6 +211,7 @@ mod tests {
207211
assert_eq!(expected_output, debug_output);
208212
}
209213

214+
#[cfg(feature = "eq")]
210215
#[test]
211216
fn eq() {
212217
let mut first_table = EnumTable::<LetterDebugDerived, i32>::new();

0 commit comments

Comments
 (0)