1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! One source of ids, for the two things in this crate that need them.
//!
//! A [`MutationId`](crate::MutationId) the cluster deduplicates a repeated
//! command by, and the trace and span ids in a
//! [`TraceContext`](crate::TraceContext). They want the same thing from an id
//! and they wanted it in the same way, so they ask for it in one place: two
//! copies of this would mean the uniqueness argument had to stay true twice,
//! and a fix to one of them — a different clock, a real random source, the
//! truncation below — would land in one and not the other.
use ;
/// Counts calls, so two words drawn in the same nanosecond still differ.
static WORDS: AtomicU64 = new;
/// Sixty-four bits unlikely to have been produced before.
///
/// The entropy comes from `RandomState`, which the standard library seeds from
/// the OS once per process, mixed with a counter and the clock. Both callers
/// need an id to be *unique*, not unpredictable, and that is a poor reason to
/// add a random-number crate to a dependency list this short.
///
/// A third caller leans on a property between those two: the heavy-proxy pool
/// (`http::HeavyPool::pick`) indexes with `word() % n` and needs the result
/// **roughly uniform**, or the pool degenerates toward a pinned pick — the
/// load-spreading it exists for. The hash of a counter delivers that; a
/// rewrite of this function into something patterned (the bare counter, say)
/// would still satisfy "unique" and silently break that caller.
///
/// `salt` separates the several words that make up one id. A fresh
/// `RandomState` per call already has its own keys, so two words are not two
/// views of one 64-bit value; the salt says so at the call site as well.
pub