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
//! Document identifiers: [`unique`] generates one, [`custom`] takes one given.
//!
//! PHP: `Utopia\Database\Id`.
use crate;
/// The random hex characters [`unique`] appends to the time-based part.
pub const PADDING: i64 = 7;
/// A new unique ID: 13 hex characters of the current time (`uniqid()`),
/// then [`PADDING`] random hex characters (20 characters in all).
///
/// ```
/// use utopia_database::id;
///
/// let id = id::unique().unwrap();
/// assert_eq!(id.len(), 20);
/// assert!(id.bytes().all(|c| c.is_ascii_hexdigit()));
/// ```
///
/// PHP: `ID::unique()`.
/// A new unique ID with `padding` random hex characters after the 13 of
/// `uniqid()` (none when `padding` is 0 or less).
///
/// Fails like PHP when the system cannot provide random bytes.
///
/// PHP: `ID::unique($padding)`.
/// An ID given by the caller, as it is.
///
/// PHP: `ID::custom($id)`.