pub struct SourceMap { /* private fields */ }Expand description
Collects immutable source owners in insertion order without filesystem IO.
Locations retain their own owners; dropping this collection does not invalidate them. See the module example.
Implementations§
Source§impl SourceMap
impl SourceMap
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty source collection.
§Examples
assert!(adam_lang::SourceMap::new().sources().is_empty());Sourcepub fn insert(&mut self, file_name: &str, text: &str) -> SourceId
pub fn insert(&mut self, file_name: &str, text: &str) -> SourceId
Copies a file name and source text into a new immutable source owner.
Repeated insertions create distinct identities.
- Complexity: O(f + t) time and space for file name length f and text length t, plus amortized O(1) collection insertion.
§Examples
See the module example.
Sourcepub fn get(&self, source: &SourceId) -> Option<&SourceId>
pub fn get(&self, source: &SourceId) -> Option<&SourceId>
Returns the retained owner only if this collection contains source.
Coincident indices in independent collections do not match.
§Examples
let mut map = adam_lang::SourceMap::new();
let id = map.insert("file.adm2", "");
assert_eq!(map.get(&id), Some(&id));
assert!(adam_lang::SourceMap::new().get(&id).is_none());Trait Implementations§
Auto Trait Implementations§
impl !Send for SourceMap
impl !Sync for SourceMap
impl Freeze for SourceMap
impl RefUnwindSafe for SourceMap
impl Unpin for SourceMap
impl UnsafeUnpin for SourceMap
impl UnwindSafe for SourceMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more