pub struct Loc<T, L> {
pub inner: T,
pub loc: L,
}Expand description
A value wrapped along with a corresponding source code location.
Typically, Locs should be created using the WithLocation trait.
NOTE This type is designed to be transparent, i.e. it behaves as T in many cases. In
particular, comparisons such as Hash, PartialEq, PartialOrd, etc. completely ignore the location
and only compare T.
In addition, the type implements Deref<Target=T> which means that Loc<T> can be passed
directly to functions which expect &T
Fields§
§inner: T§loc: LImplementations§
Source§impl<T, L> Loc<T, L>where
L: Location,
impl<T, L> Loc<T, L>where
L: Location,
pub fn new(inner: T, loc: L) -> Self
Sourcepub fn nowhere(inner: T) -> Self
pub fn nowhere(inner: T) -> Self
Create a Location which does not correspond to a source code location.
Depending on how the lbirary is used in a compiler, this can either be a placeholder
value, in which case encountering a nowhere when reporting an error
is probably an error, or if source locations can be missing it should be an actual
marker.
pub fn separate_loc(self) -> (Self, Loc<(), L>)
pub fn split(self) -> (T, L)
pub fn split_ref(&self) -> (&T, L)
pub fn split_loc(self) -> (T, Loc<(), L>)
pub fn split_loc_ref(&self) -> (&T, Loc<(), L>)
pub fn map<Y>(self, op: impl FnMut(T) -> Y) -> Loc<Y, L>
pub fn map_ref<Y>(&self, op: impl FnMut(&T) -> Y) -> Loc<Y, L>
pub fn try_map_ref<Y, E, F>(&self, op: F) -> Result<Loc<Y, L>, E>
pub fn loc(&self) -> Loc<(), L>
Trait Implementations§
Source§impl<'de, T, L> Deserialize<'de> for Loc<T, L>where
T: Deserialize<'de>,
L: Deserialize<'de>,
impl<'de, T, L> Deserialize<'de> for Loc<T, L>where
T: Deserialize<'de>,
L: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T, L> Ord for Loc<T, L>where
T: Ord,
impl<T, L> Ord for Loc<T, L>where
T: Ord,
Source§impl<T, L> PartialOrd for Loc<T, L>where
T: PartialOrd,
impl<T, L> PartialOrd for Loc<T, L>where
T: PartialOrd,
impl<T: Copy, L: Copy> Copy for Loc<T, L>
impl<T, L> Eq for Loc<T, L>where
T: Eq,
Auto Trait Implementations§
impl<T, L> Freeze for Loc<T, L>
impl<T, L> RefUnwindSafe for Loc<T, L>where
T: RefUnwindSafe,
L: RefUnwindSafe,
impl<T, L> Send for Loc<T, L>
impl<T, L> Sync for Loc<T, L>
impl<T, L> Unpin for Loc<T, L>
impl<T, L> UnwindSafe for Loc<T, L>where
T: UnwindSafe,
L: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, L> WithLocation<L> for T
impl<T, L> WithLocation<L> for T
Source§fn at_loc<T: Sized>(self, loc: &Loc<T, L>) -> Loc<Self, L>
fn at_loc<T: Sized>(self, loc: &Loc<T, L>) -> Loc<Self, L>
Source§fn between(self, start: impl Into<L>, end: impl Into<L>) -> Loc<Self, L>
fn between(self, start: impl Into<L>, end: impl Into<L>) -> Loc<Self, L>
start and endSource§fn between_locs<T, Y>(self, start: &Loc<T, L>, end: &Loc<Y, L>) -> Loc<Self, L>
fn between_locs<T, Y>(self, start: &Loc<T, L>, end: &Loc<Y, L>) -> Loc<Self, L>
start and endSource§fn nowhere(self) -> Loc<Self, L>where
Self: Sized,
fn nowhere(self) -> Loc<Self, L>where
Self: Sized,
nowhere when reporting an error
is probably an error, or if source locations can be missing it should be an actual
marker.