Skip to main content

detect_style

Function detect_style 

Source
pub fn detect_style(input: &str) -> Style
Expand description

Detect the docstring style from its content.

Uses heuristics to identify the style:

  1. NumPy: Section headers followed by --- underlines
  2. Google: Section headers ending with : (e.g., Args:, Returns:)
  3. Falls back to Google if no style-specific patterns are found

ยงExample

use pydocstring::detect_style;
use pydocstring::Style;

let numpy = "Summary.\n\nParameters\n----------\nx : int\n    Description.";
assert_eq!(detect_style(numpy), Style::NumPy);

let google = "Summary.\n\nArgs:\n    x: Description.";
assert_eq!(detect_style(google), Style::Google);