Skip to main content

Stmt

Struct Stmt 

Source
pub struct Stmt<'arena, 'src> {
    pub kind: StmtKind<'arena, 'src>,
    pub span: Span,
    pub doc_comment: Option<&'arena Comment<'src>>,
}

Fields§

§kind: StmtKind<'arena, 'src>§span: Span§doc_comment: Option<&'arena Comment<'src>>

The immediately preceding /** */ doc-block, if any.

Only /** */ (doc-block) comments are attached here; //, #, and /* */ comments remain in [ParseResult::comments]. When present, this comment is removed from ParseResult::comments — the two collections are disjoint. A doc-block that has no following statement before the enclosing } or EOF is not attached and stays in ParseResult::comments.

For declaration statements (function, class, interface, …) the doc-block is attached to the inner declaration node (e.g. FunctionDecl::doc_comment) and this field will always be None.

Stored as a pointer into the arena rather than inline so that the None case (the vast majority of statements) costs only 8 bytes instead of the 32 bytes an inline Option<Comment> would require.

Implementations§

Source§

impl<'arena, 'src> Stmt<'arena, 'src>

Source

pub fn leading_doc_comment(&self) -> Option<&Comment<'src>>

The leading /** */ doc-block for this statement, regardless of where it is stored.

For non-declaration statements (foreach, if, assignments, …) the comment lives on Stmt::doc_comment and is returned directly.

For declaration statements the comment is stored on the inner declaration node — this method checks each variant so callers do not need to match on StmtKind:

Returns None when no doc-block precedes the statement.

Trait Implementations§

Source§

impl<'arena, 'src> Debug for Stmt<'arena, 'src>

Source§

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

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

impl<'arena, 'src> Serialize for Stmt<'arena, 'src>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'arena, 'src> Freeze for Stmt<'arena, 'src>

§

impl<'arena, 'src> !RefUnwindSafe for Stmt<'arena, 'src>

§

impl<'arena, 'src> !Send for Stmt<'arena, 'src>

§

impl<'arena, 'src> !Sync for Stmt<'arena, 'src>

§

impl<'arena, 'src> Unpin for Stmt<'arena, 'src>

§

impl<'arena, 'src> UnsafeUnpin for Stmt<'arena, 'src>

§

impl<'arena, 'src> !UnwindSafe for Stmt<'arena, '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.