use core::marker::PhantomData;
use super::{Lexer, Span};
#[repr(transparent)]
pub struct Cursor<'a, 'closure, L: Lexer<'a>> {
pub(crate) span: L::Span,
_phantom: PhantomData<fn(&'closure ()) -> &'closure ()>,
}
impl<'a, L: Lexer<'a>> core::fmt::Debug for Cursor<'a, '_, L> {
#[cfg_attr(not(tarpaulin), inline(always))]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Cursor({:?})", self.span.end_ref())
}
}
impl<'a, L: Lexer<'a>> Clone for Cursor<'a, '_, L> {
#[cfg_attr(not(tarpaulin), inline(always))]
fn clone(&self) -> Self {
Self {
span: self.span.clone(),
_phantom: PhantomData,
}
}
}
impl<'a, L: Lexer<'a>> Copy for Cursor<'a, '_, L> where L::Span: Copy {}
impl<'a, L: Lexer<'a>> Cursor<'a, '_, L> {
#[cfg_attr(not(tarpaulin), inline(always))]
pub(super) const fn new(span: L::Span) -> Self {
Self {
span,
_phantom: PhantomData,
}
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(super) const fn from_ref(cursor: &L::Span) -> &Self {
unsafe { &*(cursor as *const L::Span as *const Self) }
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub(super) const fn span(&self) -> &L::Span {
&self.span
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn as_inner(&self) -> &L::Offset {
self.span.end_ref()
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn into_inner(self) -> L::Offset {
self.span.into_range().end
}
}