Skip to main content

pydocstring/
lib.rs

1//! # pydocstring
2//!
3//! A fast, zero-dependency Rust parser for Python docstrings with full AST and
4//! source location tracking. Supports **NumPy** and **Google** styles.
5//!
6//! ## Quick Start
7//!
8//! ```rust
9//! use pydocstring::numpy::{parse_numpy, nodes::NumPyDocstring};
10//!
11//! let docstring = r#"
12//! Brief description.
13//!
14//! Parameters
15//! ----------
16//! x : int
17//!     The first parameter.
18//! "#;
19//!
20//! let result = parse_numpy(docstring);
21//! let doc = NumPyDocstring::cast(result.root()).unwrap();
22//! assert_eq!(doc.summary().unwrap().text(result.source()), "Brief description.");
23//! ```
24//!
25//! ## Style Auto-Detection
26//!
27//! ```rust
28//! use pydocstring::{detect_style, Style};
29//!
30//! let numpy_doc = "Summary.\n\nParameters\n----------\nx : int\n    Desc.";
31//! assert_eq!(detect_style(numpy_doc), Style::NumPy);
32//!
33//! let google_doc = "Summary.\n\nArgs:\n    x: Desc.";
34//! assert_eq!(detect_style(google_doc), Style::Google);
35//! ```
36//!
37//! ## Features
38//!
39//! - Zero external dependencies — pure Rust
40//! - Accurate source spans (byte offsets) on every AST node
41//! - NumPy style: fully supported
42//! - Google style: fully supported
43
44pub(crate) mod cursor;
45pub mod styles;
46pub mod syntax;
47pub mod text;
48
49pub use styles::Style;
50pub use styles::detect_style;
51pub use styles::google::{self, GoogleSectionKind};
52pub use styles::numpy::{self, NumPySectionKind};
53pub use syntax::{Parsed, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, Visitor, walk};
54pub use text::{TextRange, TextSize};