diff --git a/src/lib.rs b/src/lib.rs index 8c146bf..1973716 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,38 +8,36 @@ //! //! aHash uses the hardware AES instruction on x86 processors to provide a keyed hash function. //! aHash is not a cryptographically secure hash. -//! -#![cfg_attr(any(feature = "compile-time-rng", feature = "runtime-rng"), doc = r##" -# Example -``` -use ahash::{AHasher, RandomState}; -use std::collections::HashMap; - -let mut map: HashMap = HashMap::default(); -map.insert(12, 34); -``` -"##)] -#![cfg_attr(feature = "std", doc = r##" -For convenience, both new-type wrappers and type aliases are provided. The new type wrappers are called called `AHashMap` and `AHashSet`. These do the same thing with slightly less typing. -The type aliases are called `ahash::HashMap`, `ahash::HashSet` are also provided and alias the -std::[HashMap] and std::[HashSet]. Why are there two options? The wrappers are convenient but -can't be used where a generic `std::collection::HashMap` is required. - -``` -use ahash::AHashMap; - -let mut map: AHashMap = AHashMap::with_capacity(4); -map.insert(12, 34); -map.insert(56, 78); -// There are also type aliases provieded together with some extension traits to make -// it more of a drop in replacement for the std::HashMap/HashSet -use ahash::{HashMapExt, HashSetExt}; // Used to get with_capacity() -let mut map = ahash::HashMap::with_capacity(10); -map.insert(12, 34); -let mut set = ahash::HashSet::with_capacity(10); -set.insert(10); -``` -"##)] +//! +//! # Example +//! ``` +//! use ahash::{AHasher, RandomState}; +//! use std::collections::HashMap; +//! +//! let mut map: HashMap = HashMap::default(); +//! map.insert(12, 34); +//! ``` +//! +//! For convenience, both new-type wrappers and type aliases are provided. The new type wrappers are called called `AHashMap` and `AHashSet`. These do the same thing with slightly less typing. +//! The type aliases are called `ahash::HashMap`, `ahash::HashSet` are also provided and alias the +//! std::[HashMap] and std::[HashSet]. Why are there two options? The wrappers are convenient but +//! can't be used where a generic `std::collection::HashMap` is required. +//! +//! ``` +//! use ahash::AHashMap; +//! +//! let mut map: AHashMap = AHashMap::with_capacity(4); +//! map.insert(12, 34); +//! map.insert(56, 78); +//! // There are also type aliases provieded together with some extension traits to make +//! // it more of a drop in replacement for the std::HashMap/HashSet +//! use ahash::{HashMapExt, HashSetExt}; // Used to get with_capacity() +//! let mut map = ahash::HashMap::with_capacity(10); +//! map.insert(12, 34); +//! let mut set = ahash::HashSet::with_capacity(10); +//! set.insert(10); +//! ``` + #![deny(clippy::correctness, clippy::complexity, clippy::perf)] #![allow(clippy::pedantic, clippy::cast_lossless, clippy::unreadable_literal)] #![cfg_attr(all(not(test), not(feature = "std")), no_std)] diff --git a/src/random_state.rs b/src/random_state.rs index cd15f92..4205360 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -301,26 +301,26 @@ impl BuildHasher for RandomState { /// [AHasher]s that will return different hashcodes, but [Hasher]s created from the same [BuildHasher] /// will generate the same hashes for the same input data. /// - #[cfg_attr(any(feature = "compile-time-rng", feature = "runtime-rng"), doc = r##" # Examples -``` - use ahash::{AHasher, RandomState}; - use std::hash::{Hasher, BuildHasher}; - - let build_hasher = RandomState::new(); - let mut hasher_1 = build_hasher.build_hasher(); - let mut hasher_2 = build_hasher.build_hasher(); - - hasher_1.write_u32(1234); - hasher_2.write_u32(1234); - - assert_eq!(hasher_1.finish(), hasher_2.finish()); - - let other_build_hasher = RandomState::new(); - let mut different_hasher = other_build_hasher.build_hasher(); - different_hasher.write_u32(1234); - assert_ne!(different_hasher.finish(), hasher_1.finish()); -``` - "##)] + /// # Examples + /// ``` + /// use ahash::{AHasher, RandomState}; + /// use std::hash::{Hasher, BuildHasher}; + // + /// let build_hasher = RandomState::new(); + /// let mut hasher_1 = build_hasher.build_hasher(); + /// let mut hasher_2 = build_hasher.build_hasher(); + // + /// hasher_1.write_u32(1234); + /// hasher_2.write_u32(1234); + // + /// assert_eq!(hasher_1.finish(), hasher_2.finish()); + // + /// let other_build_hasher = RandomState::new(); + /// let mut different_hasher = other_build_hasher.build_hasher(); + /// different_hasher.write_u32(1234); + /// assert_ne!(different_hasher.finish(), hasher_1.finish()); + /// ``` + /// /// [Hasher]: std::hash::Hasher /// [BuildHasher]: std::hash::BuildHasher /// [HashMap]: std::collections::HashMap