Skip to content

Commit 254ffbd

Browse files
pitajudoprog
andauthored
Introduce Entry API (#31)
Co-authored-by: John-John Tedro <udoprog@tedro.se>
1 parent 5058f33 commit 254ffbd

File tree

23 files changed

+2222
-43
lines changed

23 files changed

+2222
-43
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
- uses: actions-rs/toolchain@v1
3636
with: { toolchain: beta, override: true, profile: minimal }
3737
# Test all relevant feature combos:
38-
# features: std, map, serde
38+
# features: std, map, entry, serde
3939
- run: cargo test --all-features
40-
# features: -std, -map, -serde
40+
# features: -std, -map, -entry, -serde
4141
- run: cargo test --no-default-features
42-
# features: -std, -map, serde
42+
# features: -std, -map, -entry, serde
4343
- run: cargo test --no-default-features --features serde

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Cargo.lock
22
/target
33
/fixed-map-derive/target
44
**/*.rs.bk
5+
.vscode

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ categories = ["data-structures"]
1717
all-features = true
1818

1919
[features]
20-
default = ["map", "std"]
20+
default = ["map", "std", "entry"]
2121
std = ["serde?/std"]
2222
map = ["hashbrown", "std"]
23+
entry = ["fixed-map-derive/entry"]
2324

2425
[dependencies]
2526
fixed-map-derive = { version = "0.8.0-alpha.2", path = "fixed-map-derive" }
@@ -39,4 +40,6 @@ name = "simple"
3940
harness = false
4041

4142
[workspace]
42-
members = ["fixed-map-derive"]
43+
members = [
44+
"fixed-map-derive"
45+
]

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ assert!(!set.contains(Key::East));
6363

6464
The following features are available:
6565

66-
* `std` - Disabling this feature enables causes this crate to be no-std.
66+
* `std` - Disabling this feature causes this crate to be no-std.
6767
This means that dynamic types cannot be used in keys, like ones enabled by
6868
the `map` feature (default).
6969
* `map` - Causes [`Storage`] to be implemented by dynamic types such as
7070
`&'static str` or `u32`. These are backed by a `hashbrown` (default).
71+
* `entry` - Enables an [`entry`] API similar to that found on [`HashMap`].
7172
* `serde` - Causes [`Map`] and [`Set`] to implement [`Serialize`] and
7273
[`Deserialize`] if it's implemented by the key and value.
7374

@@ -176,6 +177,11 @@ if let Some(item) = map.get(Dir::North) {
176177
}
177178
```
178179

180+
## Unsafe use
181+
The Entry API uses `unwrap_unchecked` to obtain
182+
mutable references to the inner value of `Some`s,
183+
and to skip `drop` when overwriting `None`s.
184+
179185
<br>
180186

181187
## Benchmarks
@@ -263,6 +269,8 @@ ls target/release/examples/
263269
[`Key` derive]: https://docs.rs/fixed-map/latest/fixed_map/derive.Key.html
264270
[`Key`]: https://docs.rs/fixed-map/latest/fixed_map/derive.Key.html
265271
[`Map`]: https://docs.rs/fixed-map/latest/fixed_map/map/struct.Map.html
272+
[`entry`]: https://docs.rs/fixed-map/latest/fixed_map/map/struct.Map.html#method.entry
273+
[`HashMap`]: https://doc.rust-lang.org/stable/std/collections/hash_map/struct.HashMap.html#method.entry
266274
[`Serialize`]: https://docs.rs/serde/1/serde/trait.Serialize.html
267275
[`Set`]: https://docs.rs/fixed-map/latest/fixed_map/set/struct.Set.html
268276
[`Storage`]: https://docs.rs/fixed-map/latest/fixed_map/storage/trait.Storage.html

fixed-map-derive/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ license = "MIT/Apache-2.0"
1616
keywords = ["container", "data-structure", "map", "no_std"]
1717
categories = ["data-structures"]
1818

19+
[features]
20+
entry = ["fixed-map/entry"]
21+
1922
[dependencies]
2023
syn = "1.0.8"
2124
quote = "1.0.2"

0 commit comments

Comments
 (0)