pydocstring 0.1.13

A zero-dependency Rust parser for Python docstrings (Google and NumPy styles) with a unified syntax tree and byte-precise source locations
Documentation
//! Typed wrapper for the plain-style docstring root node.

use crate::syntax::{SyntaxKind, SyntaxNode, SyntaxToken};

// =============================================================================
// PlainDocstring
// =============================================================================

/// Typed wrapper for [`SyntaxKind::PLAIN_DOCSTRING`] nodes.
#[derive(Debug)]
pub struct PlainDocstring<'a>(pub(crate) &'a SyntaxNode);

impl<'a> PlainDocstring<'a> {
    /// Try to cast a `SyntaxNode` reference into this typed wrapper.
    pub fn cast(node: &'a SyntaxNode) -> Option<Self> {
        (node.kind() == SyntaxKind::PLAIN_DOCSTRING).then_some(Self(node))
    }

    /// Access the underlying `SyntaxNode`.
    pub fn syntax(&self) -> &'a SyntaxNode {
        self.0
    }

    /// Brief summary token, if present.
    pub fn summary(&self) -> Option<&'a SyntaxToken> {
        self.0.find_token(SyntaxKind::SUMMARY)
    }

    /// Extended summary token, if present.
    pub fn extended_summary(&self) -> Option<&'a SyntaxToken> {
        self.0.find_token(SyntaxKind::EXTENDED_SUMMARY)
    }
}