use crate::{Location, Meta, Span};
pub type Loc<T, F, S = Span> = Meta<T, Location<F, S>>;
#[allow(non_snake_case)]
#[doc(hidden)]
#[inline(always)]
pub fn Loc<T, F, S>(t: T, location: Location<F, S>) -> Loc<T, F, S> {
Meta(t, location)
}
impl<T, F, S> Loc<T, F, S> {
pub fn into_location(self) -> Location<F, S> {
self.into_metadata()
}
#[inline(always)]
pub fn into_file(self) -> F {
self.1.into_file()
}
#[inline(always)]
pub fn into_span(self) -> S {
self.1.into_span()
}
#[inline(always)]
pub fn location(&self) -> &Location<F, S> {
self.metadata()
}
#[inline(always)]
pub fn location_mut(&mut self) -> &mut Location<F, S> {
self.metadata_mut()
}
#[inline(always)]
pub fn span(&self) -> S
where
S: Clone,
{
self.1.span()
}
#[inline(always)]
pub fn span_mut(&mut self) -> &mut S {
self.1.span_mut()
}
#[inline(always)]
pub fn set_span(&mut self, span: S) -> S {
self.1.set_span(span)
}
#[inline(always)]
pub fn file(&self) -> &F {
self.1.file()
}
#[inline(always)]
pub fn file_mut(&mut self) -> &mut F {
self.1.file_mut()
}
#[inline(always)]
pub fn set_file(&mut self, file: F) -> F {
self.1.set_file(file)
}
#[inline(always)]
pub fn map_location<G, U>(
self,
f: impl FnOnce(Location<F, S>) -> Location<G, U>,
) -> Loc<T, G, U> {
Loc(self.0, f(self.1))
}
#[inline(always)]
pub fn map_file<G>(self, f: impl FnOnce(F) -> G) -> Loc<T, G, S> {
Loc(self.0, self.1.map_file(f))
}
#[inline(always)]
pub fn borrow_value_and_file(&self) -> Loc<&T, &F, S>
where
T: Clone,
S: Clone,
{
Loc(&self.0, self.1.borrow())
}
#[inline(always)]
pub fn borrow_file(&self) -> Loc<T, &F, S>
where
T: Clone,
S: Clone,
{
Meta(self.0.clone(), self.1.borrow())
}
}
impl<'f, T, F: Clone, S: Clone> Loc<T, &'f F, S> {
#[inline(always)]
pub fn cloned_file(&self) -> Loc<T, F, S>
where
T: Clone,
{
Loc(self.0.clone(), self.1.cloned())
}
#[inline(always)]
pub fn into_cloned_file(self) -> Loc<T, F, S> {
Loc(self.0, self.1.cloned())
}
}
impl<'t, 'f, T: Clone, F: Clone, S: Clone> Loc<&'t T, &'f F, S> {
pub fn cloned(&self) -> Loc<T, F, S> {
Loc(self.0.clone(), self.1.cloned())
}
}