pub struct SourcePos(_);
Expand description
Swc unfortunately uses BytePos(0)
as a magic value. This means
that we can’t have byte positions of nodes line up with the text.
To get around this, we have created our own SourcePos
wrapper
that hides the underlying swc byte position so it can’t be used
incorrectly.
Implementations
sourceimpl SourcePos
impl SourcePos
pub fn as_byte_pos(&self) -> BytePos
pub fn as_byte_index(&self, start_pos: StartSourcePos) -> usize
sourcepub fn unsafely_from_byte_pos(byte_pos: BytePos) -> SourcePos
pub fn unsafely_from_byte_pos(byte_pos: BytePos) -> SourcePos
Do not use this except when receiving an swc byte position
from swc and needing to convert it to a source position.
If you need to create a SourcePos
then you should get
the text info’s start position and add to it in order to
get a new source position.
Trait Implementations
sourceimpl Into<SourcePos> for StartSourcePos
impl Into<SourcePos> for StartSourcePos
sourceimpl Ord for SourcePos
impl Ord for SourcePos
sourceimpl PartialEq<SourcePos> for StartSourcePos
impl PartialEq<SourcePos> for StartSourcePos
sourceimpl PartialEq<StartSourcePos> for SourcePos
impl PartialEq<StartSourcePos> for SourcePos
sourceimpl PartialOrd<SourcePos> for StartSourcePos
impl PartialOrd<SourcePos> for StartSourcePos
sourcefn partial_cmp(&self, other: &SourcePos) -> Option<Ordering>
fn partial_cmp(&self, other: &SourcePos) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<SourcePos> for SourcePos
impl PartialOrd<SourcePos> for SourcePos
sourcefn partial_cmp(&self, other: &SourcePos) -> Option<Ordering>
fn partial_cmp(&self, other: &SourcePos) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<StartSourcePos> for SourcePos
impl PartialOrd<StartSourcePos> for SourcePos
sourcefn partial_cmp(&self, other: &StartSourcePos) -> Option<Ordering>
fn partial_cmp(&self, other: &StartSourcePos) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl SourceRanged for SourcePos
impl SourceRanged for SourcePos
fn start(&self) -> SourcePos
fn end(&self) -> SourcePos
fn range(&self) -> SourceRange<SourcePos>
fn byte_width(&self) -> usize
fn start_line_fast(&self, source: &dyn SourceTextInfoProvider<'_>) -> usize
fn end_line_fast(&self, source: &dyn SourceTextInfoProvider<'_>) -> usize
fn start_column_fast(&self, source: &dyn SourceTextInfoProvider<'_>) -> usize
fn end_column_fast(&self, source: &dyn SourceTextInfoProvider<'_>) -> usize
fn column_at_pos(
&self,
source: &dyn SourceTextInfoProvider<'_>,
pos: SourcePos
) -> usize
fn char_width_fast(&self, source: &dyn SourceTextInfoProvider<'_>) -> usize
fn text_fast(&self, source: &dyn SourceTextInfoProvider<'a>) -> &'a str
fn tokens_fast(&self, program: &dyn RootNode<'a>) -> &'a [TokenAndSpan]
fn leading_comments_fast(
&self,
program: &dyn RootNode<'a>
) -> CommentsIterator<'a>ⓘNotable traits for CommentsIterator<'a>impl<'a> Iterator for CommentsIterator<'a> type Item = &'a Comment;
fn trailing_comments_fast(
&self,
program: &dyn RootNode<'a>
) -> CommentsIterator<'a>ⓘNotable traits for CommentsIterator<'a>impl<'a> Iterator for CommentsIterator<'a> type Item = &'a Comment;
fn previous_token_fast(
&self,
program: &dyn RootNode<'a>
) -> Option<&'a TokenAndSpan>
fn next_token_fast(
&self,
program: &dyn RootNode<'a>
) -> Option<&'a TokenAndSpan>
fn previous_tokens_fast(&self, program: &dyn RootNode<'a>) -> &'a [TokenAndSpan]
fn next_tokens_fast(&self, program: &dyn RootNode<'a>) -> &'a [TokenAndSpan]
sourceimpl Sub<StartSourcePos> for SourcePos
impl Sub<StartSourcePos> for SourcePos
sourcefn sub(self, rhs: StartSourcePos) -> <SourcePos as Sub<StartSourcePos>>::Output
fn sub(self, rhs: StartSourcePos) -> <SourcePos as Sub<StartSourcePos>>::Output
Performs the -
operation. Read more
impl Copy for SourcePos
impl Eq for SourcePos
impl StructuralEq for SourcePos
impl StructuralPartialEq for SourcePos
Auto Trait Implementations
impl RefUnwindSafe for SourcePos
impl Send for SourcePos
impl Sync for SourcePos
impl Unpin for SourcePos
impl UnwindSafe for SourcePos
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more