Skip to content

Commit

Permalink
Remove conditional compilation from example code
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Oct 14, 2022
1 parent 4246227 commit 307f5a6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 52 deletions.
62 changes: 30 additions & 32 deletions src/lib.rs
Expand Up @@ -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<i32, i32, RandomState> = 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<K, V, S>` is required.
```
use ahash::AHashMap;
let mut map: AHashMap<i32, i32> = 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<i32, i32, RandomState> = 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<K, V, S>` is required.
//!
//! ```
//! use ahash::AHashMap;
//!
//! let mut map: AHashMap<i32, i32> = 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)]
Expand Down
40 changes: 20 additions & 20 deletions src/random_state.rs
Expand Up @@ -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
Expand Down

0 comments on commit 307f5a6

Please sign in to comment.