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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use ;
use crateReader;
/// Serializes the strings from an interner as a sequence, in [`Reader`] iteration
/// order.
///
/// # Handle preservation requires a matching layout
///
/// The serialized form is a bare string sequence; it does **not** record which
/// engine produced it. Deserializing it rebuilds handles from scratch, so the
/// reconstructed [`Sym`](crate::Sym) values equal the originals **only when the
/// target engine reproduces the source engine's handle layout**:
///
/// - A reader from a [`LocalLexicon`](crate::LocalLexicon) (dense layout)
/// preserves handles only when restored into a
/// [`LocalLexicon`](crate::LocalLexicon).
/// - A reader from a [`ThreadedLexicon`](crate::ThreadedLexicon) (sharded layout)
/// preserves handles only when restored into a
/// [`ThreadedLexicon`](crate::ThreadedLexicon) using its default hasher and the
/// same shard count.
///
/// Crossing engines (flat sequence → `ThreadedLexicon`, or sharded sequence →
/// `LocalLexicon`) still restores the same *strings*, but assigns different
/// handles, so a persisted `Sym` may then refer to a different string. When only
/// the strings matter, any engine is fine; when handle identity must survive,
/// restore into the matching engine.
///
/// ```
/// use internity::LocalLexicon;
/// use internity::se::SerializeReader;
///
/// let mut lexicon = LocalLexicon::new();
/// lexicon.intern("a");
/// lexicon.intern("b");
/// let reader = lexicon.freeze();
/// let json = serde_json::to_string(&SerializeReader(&reader)).unwrap();
/// assert_eq!(json, r#"["a","b"]"#);
/// ```
;