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
84
85
86
87
88
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//! The [`Reader`] trait: a read-only, `Send + Sync` view of an interner.
use Box;
use crateSym;
/// Sealing module: `Reader` extends `sealed::Sealed`, which only this crate can
/// implement, so `Reader` cannot be implemented downstream. This lets the crate
/// add methods to `Reader` without a breaking change.
pub use Sealed;
/// A read-only view of an interner, optimized for fast lookups.
///
/// A `Reader` is `Send + Sync` and its [`resolve`](Reader::resolve) is lock-free,
/// so you can share it across threads (e.g. behind an `Arc`) and resolve handles
/// concurrently. Handles produced by the source interner stay valid.
///
/// [`LocalLexicon`](crate::LocalLexicon) implements this trait directly. Calling
/// [`LocalLexicon::freeze`](crate::LocalLexicon::freeze) or
/// [`ThreadedLexicon::freeze`](crate::ThreadedLexicon::freeze) returns an
/// immutable `impl Reader`. Bring this trait into scope to call its methods
/// (`use internity::Reader`), and use `impl Reader` / `Box<dyn Reader>` when you
/// need to abstract over reader implementations.
///
/// This trait is [sealed](https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed):
/// it cannot be implemented outside this crate.
///
/// # Examples
///
/// ```
/// use internity::{LocalLexicon, Reader};
///
/// let mut lexicon = LocalLexicon::new();
/// let a = lexicon.intern("hello");
/// assert_eq!(Reader::resolve(&lexicon, a), "hello");
/// assert_eq!(Reader::try_resolve(&lexicon, a), Some("hello"));
/// ```