Skip to main content

SourceMap

Struct SourceMap 

Source
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

Source

pub fn new() -> Self

Creates an empty source collection.

§Examples
assert!(adam_lang::SourceMap::new().sources().is_empty());
Source

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.

Source

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());
Source

pub fn sources(&self) -> &[SourceId]

Borrows source owners in insertion order.

§Examples

See Self::new.

Trait Implementations§

Source§

impl Debug for SourceMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SourceMap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.