pub struct SourcePos(/* private fields */);
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§
source§impl 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§
source§impl Into<SourcePos> for StartSourcePos
impl Into<SourcePos> for StartSourcePos
source§impl Ord for SourcePos
impl Ord for SourcePos
source§impl PartialEq<SourcePos> for StartSourcePos
impl PartialEq<SourcePos> for StartSourcePos
source§impl PartialEq<StartSourcePos> for SourcePos
impl PartialEq<StartSourcePos> for SourcePos
source§fn eq(&self, other: &StartSourcePos) -> bool
fn eq(&self, other: &StartSourcePos) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq for SourcePos
impl PartialEq for SourcePos
source§impl PartialOrd<SourcePos> for StartSourcePos
impl PartialOrd<SourcePos> for StartSourcePos
1.0.0 · source§fn 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 moresource§impl PartialOrd<StartSourcePos> for SourcePos
impl PartialOrd<StartSourcePos> for SourcePos
source§fn partial_cmp(&self, other: &StartSourcePos) -> Option<Ordering>
fn partial_cmp(&self, other: &StartSourcePos) -> Option<Ordering>
1.0.0 · source§fn 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 moresource§impl PartialOrd for SourcePos
impl PartialOrd for SourcePos
1.0.0 · source§fn 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 moresource§impl SourceRanged for SourcePos
impl SourceRanged for SourcePos
fn start(&self) -> SourcePos
fn end(&self) -> SourcePos
fn range(&self) -> SourceRange
fn byte_width(&self) -> usize
fn start_line_fast<'a, P>(&self, source: P) -> usizewhere
P: SourceTextInfoProvider<'a>,
fn end_line_fast<'a, P>(&self, source: P) -> usizewhere
P: SourceTextInfoProvider<'a>,
fn start_column_fast<'a, P>(&self, source: P) -> usizewhere
P: SourceTextInfoProvider<'a>,
fn end_column_fast<'a, P>(&self, source: P) -> usizewhere
P: SourceTextInfoProvider<'a>,
fn column_at_pos<'a, P>(&self, source: P, pos: SourcePos) -> usizewhere
P: SourceTextInfoProvider<'a>,
fn char_width_fast<'a, P>(&self, source: P) -> usizewhere
P: SourceTextInfoProvider<'a>,
fn text_fast<'a, P>(&self, source: P) -> &'a strwhere
P: SourceTextInfoProvider<'a>,
fn tokens_fast<'a>(&self, program: impl RootNode<'a>) -> &'a [TokenAndSpan]
fn leading_comments_fast<'a>( &self, program: impl RootNode<'a> ) -> CommentsIterator<'a> ⓘ
fn trailing_comments_fast<'a>( &self, program: impl RootNode<'a> ) -> CommentsIterator<'a> ⓘ
fn previous_token_fast<'a>( &self, program: impl RootNode<'a> ) -> Option<&'a TokenAndSpan>
fn next_token_fast<'a>( &self, program: impl RootNode<'a> ) -> Option<&'a TokenAndSpan>
fn previous_tokens_fast<'a>( &self, program: impl RootNode<'a> ) -> &'a [TokenAndSpan]
fn next_tokens_fast<'a>(&self, program: impl RootNode<'a>) -> &'a [TokenAndSpan]
source§impl Sub<StartSourcePos> for SourcePos
impl Sub<StartSourcePos> for SourcePos
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§
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
Mutably borrows from an owned value. Read more
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.