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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Shared strings with fast copying, hashing and equality checking.
use String;
use fmt;
use ;
/// Shared string with fast cloning, hashing, and equality check.
///
/// This is implemented using a reference-counted pointer.
/// Cloning, hashing, and equality checking is performed on
/// the address of the pointer, making them constant-time operations.
///
/// Note that two different symbols pointing to equivalent strings
/// are not equal, as well as their hashes:
///
/// ~~~
/// # use kontroli::symbol::{Owned, Symbol};
/// # use std::collections::hash_map::DefaultHasher;
/// # use std::hash::{Hash, Hasher};
/// let h1 = Owned::new(String::from("Hello"));
/// let h2 = Owned::new(String::from("Hello"));
/// let wl = Owned::new(String::from("World"));
/// let s1 = Symbol::new(&h1);
/// let s2 = Symbol::new(&h2);
/// let s3 = Symbol::new(&wl);
///
/// assert_eq!(s1, s1);
/// assert_eq!(s1, s1.clone());
/// assert_ne!(s1, s2);
/// assert_ne!(s1, s3);
///
/// let hash = |s: Symbol| -> u64 {
/// let mut hasher = DefaultHasher::new();
/// s.hash(&mut hasher);
/// hasher.finish()
/// };
///
/// assert_eq!(hash(s1), hash(s1.clone()));
/// assert_ne!(hash(s1), hash(s2));
/// ~~~
///
/// To consistently assign the same symbols to equivalent strings,
/// you can use the [`Symbols`] type.
///
/// [`Symbols`]: super::Symbols
;
;