use pstd::{ alloc::Global, collections::btree_map::{BTreeMap,CustomAllocTuning} };
let a = Global {};
let mut map = BTreeMap::<_, _, CustomAllocTuning<Global>>::new_in(a);
map.insert("England", "London");
It will not compile without the type specification
::<_, _, CustomAllocTuning<Global>>::
I was a bit surprised by this ( it also took me a fair while to figure out what was needed ), I am now wondering if there is anything I could do differently here.
Seems like a design mistake in the library. Basically, the BTreeMap<K, V, A1> type has a method new_in::<A2> that returns a BTreeMap<K, V, CustomAllocTuning<A2>>. So there's an extra type parameter A1 that's not used for anything, and since it's not used for anything, you have to explicitly specify it.
Hmm, I expect you are right, but I don't see what to do differently.
In case it helps, here is the error output without the explicit type:
---- src\collections\btree_map\mod.rs - collections::btree_map::BTreeMap<K,V,A>::new_in (line 97) stdout ----
error[E0283]: type annotations needed
--> src\collections\btree_map\mod.rs:101:15
|
7 | let mut map = BTreeMap::new_in(a);
| ^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `A` declared on the struct `BTreeMap`
|
= note: cannot satisfy `_: AllocTuning`
= help: the trait `AllocTuning` is implemented for `CustomAllocTuning<AL>`
note: required by a bound in `pstd::collections::BTreeMap::<K, V, A>::new_in`
--> C:\Users\ano31\Rust\pstd\src\collections\btree_map\mod.rs:89:15
|
89 | impl<K, V, A: AllocTuning> BTreeMap<K, V, A> {
| ^^^^^^^^^^^ required by this bound in `BTreeMap::<K, V, A>::new_in`
...
105 | pub fn new_in<AL>(a: AL) -> BTreeMap<K, V, CustomAllocTuning<AL>>
| ------ required by a bound in this associated function
help: consider specifying the generic arguments
|
7 | let mut map = BTreeMap::<&str, &str, A>::new_in(a);
| +++++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0283`.
Couldn't compile the test.