pub struct DecoratedComment<L: Language> { /* private fields */ }
Expand description

A comment decorated with additional information about its surrounding context in the source document.

Used by CommentStyle::place_comment to determine if this should become a leading, dangling, or trailing comment.

Implementations§

source§

impl<L: Language> DecoratedComment<L>

source

pub fn enclosing_node(&self) -> &SyntaxNode<L>

The closest parent node that fully encloses the comment.

A node encloses a comment when the comment is between two of its direct children (ignoring lists).

§Examples
[a, /* comment */ b]

The enclosing node is the array expression and not the identifier b because a and b are children of the array expression and comment is a comment between the two nodes.

source

pub fn piece(&self) -> &SyntaxTriviaPieceComments<L>

Returns the comment piece.

source

pub fn preceding_node(&self) -> Option<&SyntaxNode<L>>

Returns the node preceding the comment.

The direct child node (ignoring lists) of the enclosing_node that precedes this comment.

Returns None if the enclosing_node only consists of tokens or if all preceding children of the enclosing_node have been tokens.

The Preceding node is guaranteed to be a sibling of following_node.

§Examples
§Preceding tokens only
[/* comment */]

Returns None because the comment has no preceding node, only a preceding [ token.

§Preceding node
[a /* comment */, b]

Returns Some(a) because a directly precedes the comment.

§Preceding token and node
[a, /* comment */]

Returns Some(a) because a is the preceding node of comment. The presence of the , token doesn’t change that.

source

pub fn following_node(&self) -> Option<&SyntaxNode<L>>

Returns the node following the comment.

The direct child node (ignoring lists) of the enclosing_node that follows this comment.

Returns None if the enclosing_node only consists of tokens or if all children children of the enclosing_node following this comment are tokens.

The following node is guaranteed to be a sibling of preceding_node.

§Examples
§Following tokens only
[ /* comment */ ]

Returns None because there’s no node following the comment, only the ] token.

§Following node
[ /* comment */ a ]

Returns Some(a) because a is the node directly following the comment.

§Following token and node
async /* comment */ function test() {}

Returns Some(test) because the test identifier is the first node following comment.

§Following parenthesized expression
!(
    a /* comment */
);
b

Returns None because comment is enclosed inside the parenthesized expression and it has no children following `/* comment */.

source

pub fn lines_before(&self) -> u32

The number of line breaks between this comment and the previous token or comment.

§Examples
§Same line
a // end of line

Returns 0 because there’s no line break between the token a and the comment.

§Own Line
a;

/* comment */

Returns 2 because there are two line breaks between the token a and the comment.

source

pub fn lines_after(&self) -> u32

The number of line breaks right after this comment.

§Examples
§End of line
a; // comment

b;

Returns 2 because there are two line breaks between the comment and the token b.

§Same line
a;
/* comment */ b;

Returns 0 because there are no line breaks between the comment and the token b.

source

pub fn kind(&self) -> CommentKind

Returns the CommentKind of the comment.

source

pub fn text_position(&self) -> CommentTextPosition

The position of the comment in the text.

source

pub fn following_token(&self) -> Option<&SyntaxToken<L>>

The next token that comes after this comment. It is possible that other comments are between this comment and the token.

a /* comment */ /* other */ b

The following_token for both comments is b because it’s the token coming after the comments.

Trait Implementations§

source§

impl<L: Clone + Language> Clone for DecoratedComment<L>

source§

fn clone(&self) -> DecoratedComment<L>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<L: Debug + Language> Debug for DecoratedComment<L>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<L: Language> From<DecoratedComment<L>> for SourceComment<L>

source§

fn from(decorated: DecoratedComment<L>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<L> Freeze for DecoratedComment<L>

§

impl<L> RefUnwindSafe for DecoratedComment<L>
where L: RefUnwindSafe,

§

impl<L> !Send for DecoratedComment<L>

§

impl<L> !Sync for DecoratedComment<L>

§

impl<L> Unpin for DecoratedComment<L>
where L: Unpin,

§

impl<L> UnwindSafe for DecoratedComment<L>
where L: UnwindSafe,

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more