Here https://crates.io/crates/ahash it is said that for convenience one could do
use ahash::AHashMap;
let mut map: AHashMap<i32, i32> = AHashMap::new();
map.insert(12, 34);
map.insert(56, 78);
But one could do the following which looks even more convenient to me.
use ahash::{AHashMap as HashMap};
let mut map: HashMap<i32, i32> = HashMap::new();
map.insert(12, 34);
map.insert(56, 78);
Question: Is my version technically the same as the one given by the author of ahash
?
Technically, yes. The only possible difference would be if you've named the import the same as some item from the prelude, i.e. Vec
or Result
, since in this case explicit import would shadow the implicit one.
3 Likes
Or you could shadow items from glob imports.
I.e.
use std::collections::*;
use ahash::{AHashMap as HashMap};
Will pick ahash
's version, not the std
version
skysch
January 9, 2021, 4:39pm
4
BTW, you can write this without the brackets:
use ahash::AHashMap as HashMap;
The brackets are for grouping, so that you can do things like this:
use ahash::{AHashmap as HashMapA, BHashMap as HashMapB};
1 Like
@skysch Oh yes, thank you.
system
Closed
April 9, 2021, 6:16pm
6
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.