pinus
A prickly BTreeMap.
- You can insert through shared references and values are pin-projected.
- You can remove keys and drop entries through exclusive references.
- You can remove values through exclusive references until the
PineMapis pinned.
This container API is fine ☕🐕, but it's still fully usable without directly referencing that crate.
This crate goes together well with fruit-salad 🥗
Help wanted!
I need only a fairly barebones implementation and not necessarily optimized version of this data structure for my own project(s), but am committed to maintaining it into shape if there's interest.
Follow the "good first issues" badge above for starting points!
Note that the crate uses unsafe code very frequently, so you should be at least somewhat comfortable with ensuring soundness manually. Code reviews are also highly appreciated, both within and outside of this regard.
Installation
Please use cargo-edit to always add the latest version of this library:
cargo add pinus
Examples
Homogeneous Map
use ;
use ;
use *;
// `PineMap` is interior-mutable, so either is useful:
let map = new;
let mut mut_map = new;
// Get parallel shared references by inserting like this:
let a: &String = map.insert
.unwrap;
let b: &String = map.insert_with
.map_err.unwrap;
let c: &String = map.
.unwrap
.map_err.unwrap;
let a2: &String = map.get.unwrap;
let _ = ;
// Get exclusive references like this (also with or without factory):
let mut_a: &mut String = mut_map.insert_with_mut
.map_err.unwrap;
let mut_a2: &mut String = mut_map.get_mut.unwrap;
// The `…_mut` methods are actually faster, but their results can't be held onto at once:
// let _ = (mut_a, mut_a2); // "error[E0499]: cannot borrow `mut_map` as mutable more than once at a time"
// Remove entries like this:
mut_map.clear;
let _: = mut_map.remove_pair;
let _: = mut_map.remove_value;
let _: = mut_map.remove_key;
let _: bool = mut_map.drop_entry;
/////
// Now on to part 2, value pinning:
let mut map: = map.pin;
let mut mut_map: = mut_map.pin;
// Shared references to values are now pinned:
let a: = map.insert
.unwrap;
let b: = map.insert_with
.ok.unwrap;
let c: = map.
.unwrap.ok.unwrap;
let a2: = map.get.unwrap;
let _ = ;
// Exclusive references to values are also pinned:
let mut mut_a: = mut_map.insert_with_mut
.map_err.unwrap;
let mut mut_a2: = mut_map.get_mut.unwrap;
// The `…_mut` methods are actually faster, but their results can't be held onto at once:
// let _ = (mut_a, mut_a2); // "error[E0499]: cannot borrow `mut_map` as mutable more than once at a time"
// Only keys can be removed now, but values must be dropped in place:
mut_map.clear;
let _: = mut_map.remove_key;
let _: bool = mut_map.drop_entry;
Heterogeneous Map
use ;
use ;
use *;
let map = new;
// `dyn Any` is `!Sized`,
// so it's necessary to use the loosely-typed emplacement methods:
let _: &dyn Any = map
.emplace_with
.ok.unwrap;
let _: &dyn Any = map
.
.unwrap
.ok.unwrap;
// There's also a by-value method,
// but it has slightly steeper requirements:
;
let _: &dyn Any = map
.emplace
.unwrap;
// As usual the map's values can be pinned:
let map: = map.pin;
// And then further value references are pinned:
let _: = map.emplace.unwrap;
// To immediately get an unpinned reference, just use `.as_unpinned()`:
let _: &dyn Any = map.as_unpinned.emplace.unwrap;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
See CONTRIBUTING for more information.
Code of Conduct
Changelog
Versioning
pinus strictly follows Semantic Versioning 2.0.0 with the following exceptions:
- The minor version will not reset to 0 on major version changes (except for v1).
Consider it the global feature level. - The patch version will not reset to 0 on major or minor version changes (except for v0.1 and v1).
Consider it the global patch level.
This includes the Rust version requirement specified above.
Earlier Rust versions may be compatible, but this can change with minor or patch releases.
Which versions are affected by features and patches can be determined from the respective headings in CHANGELOG.md.
Note that dependencies of this crate may have a more lenient MSRV policy!
Please use cargo +nightly update -Z minimal-versions in your automation if you don't generate Cargo.lock manually (or as necessary) and require support for a compiler older than current stable.