Skip to main content

CommentMap

Struct CommentMap 

Source
pub struct CommentMap<'a, 'src> { /* private fields */ }
Expand description

Associates comments with statement spans using a leading-comment heuristic.

A comment is “leading” for a statement if it appears before the statement and no other statement is closer. Comments after the last statement are “trailing”.

Implementations§

Source§

impl<'a, 'src> CommentMap<'a, 'src>

Source

pub fn build<'arena>( comments: &'a [Comment<'src>], stmts: &[Stmt<'arena, 'src>], ) -> Self

Build a comment map from a list of comments and statements.

Both comments and stmts must be in source order (which they are as produced by the parser).

Source

pub fn leading_comments(&self, stmt_span: Span) -> &[&'a Comment<'src>]

Get comments that lead the statement at the given span.

Source

pub fn trailing_comments(&self) -> &[&'a Comment<'src>]

Get comments that appear after all statements.

Source

pub fn iter_leading(&self) -> impl Iterator<Item = (u32, &[&'a Comment<'src>])>

Iterate over all (stmt_start_offset, comments) pairs.

Source

pub fn is_empty(&self) -> bool

Returns true if no comments were mapped.

Source

pub fn len(&self) -> usize

Total number of comments in the map.

Auto Trait Implementations§

§

impl<'a, 'src> Freeze for CommentMap<'a, 'src>

§

impl<'a, 'src> RefUnwindSafe for CommentMap<'a, 'src>

§

impl<'a, 'src> Send for CommentMap<'a, 'src>

§

impl<'a, 'src> Sync for CommentMap<'a, 'src>

§

impl<'a, 'src> Unpin for CommentMap<'a, 'src>

§

impl<'a, 'src> UnsafeUnpin for CommentMap<'a, 'src>

§

impl<'a, 'src> UnwindSafe for CommentMap<'a, 'src>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.