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
//! Stable handles identifying a source within a map.
/// A small, copyable handle to one source in a [`SourceMap`](crate::SourceMap).
///
/// A `SourceId` is a 32-bit index minted by the map when a source is added. It
/// is stable for the life of the map: the id returned by
/// [`SourceMap::add`](crate::SourceMap::add) keeps pointing at the same source
/// no matter how many more are added afterwards, because sources are only ever
/// appended. That stability is what lets a token, an AST node, or a cached
/// diagnostic store a `SourceId` and resolve it later.
///
/// The id is deliberately opaque — there is no public constructor — so an id can
/// only come from a map that actually holds the source it names. Pass it back to
/// [`SourceMap::source`](crate::SourceMap::source) to borrow the source, or to
/// the result of [`SourceMap::locate`](crate::SourceMap::locate) to identify
/// where a global position resolved.
///
/// # Examples
///
/// ```
/// use source_lang::SourceMap;
///
/// let mut map = SourceMap::new();
/// let first = map.add("a.txt", "alpha").expect("fits");
/// let second = map.add("b.txt", "beta").expect("fits");
///
/// // Ids are assigned in order and stay distinct.
/// assert_eq!(first.to_u32(), 0);
/// assert_eq!(second.to_u32(), 1);
/// assert_ne!(first, second);
/// ```
;