pub struct Document<'a> { /* private fields */ }Expand description
Style-independent view of a parsed docstring root.
Construct with Document::new from any Parsed result, whatever the
source style.
Implementations§
Source§impl<'a> Document<'a>
impl<'a> Document<'a>
Sourcepub fn new(parsed: &'a Parsed) -> Self
pub fn new(parsed: &'a Parsed) -> Self
View the root of parsed as a style-independent document.
Examples found in repository?
examples/parse_numpy.rs (line 39)
8fn main() {
9 let docstring = r#"
10Calculate the area of a rectangle.
11
12This function takes the width and height of a rectangle
13and returns its area.
14
15Parameters
16----------
17width : float
18 The width of the rectangle.
19height : float
20 The height of the rectangle.
21
22Returns
23-------
24float
25 The area of the rectangle.
26
27Raises
28------
29ValueError
30 If width or height is negative.
31
32Examples
33--------
34>>> calculate_area(5.0, 3.0)
3515.0
36"#;
37
38 let parsed = parse_numpy(docstring);
39 let doc = Document::new(&parsed);
40
41 println!("╔══════════════════════════════════════════════════╗");
42 println!("║ NumPy-style Docstring Example ║");
43 println!("╚══════════════════════════════════════════════════╝");
44
45 println!();
46
47 // Display: raw source text
48 println!("── raw text ────────────────────────────────────────");
49 println!("{}", doc.syntax().range().source_text(parsed.source()));
50
51 println!();
52
53 // pretty_print: structured AST
54 println!("── parsed AST ──────────────────────────────────────");
55 print!("{}", parsed.pretty_print());
56}Sourcepub fn syntax(&self) -> &'a SyntaxNode
pub fn syntax(&self) -> &'a SyntaxNode
Access the underlying SyntaxNode.
Examples found in repository?
examples/parse_numpy.rs (line 49)
8fn main() {
9 let docstring = r#"
10Calculate the area of a rectangle.
11
12This function takes the width and height of a rectangle
13and returns its area.
14
15Parameters
16----------
17width : float
18 The width of the rectangle.
19height : float
20 The height of the rectangle.
21
22Returns
23-------
24float
25 The area of the rectangle.
26
27Raises
28------
29ValueError
30 If width or height is negative.
31
32Examples
33--------
34>>> calculate_area(5.0, 3.0)
3515.0
36"#;
37
38 let parsed = parse_numpy(docstring);
39 let doc = Document::new(&parsed);
40
41 println!("╔══════════════════════════════════════════════════╗");
42 println!("║ NumPy-style Docstring Example ║");
43 println!("╚══════════════════════════════════════════════════╝");
44
45 println!();
46
47 // Display: raw source text
48 println!("── raw text ────────────────────────────────────────");
49 println!("{}", doc.syntax().range().source_text(parsed.source()));
50
51 println!();
52
53 // pretty_print: structured AST
54 println!("── parsed AST ──────────────────────────────────────");
55 print!("{}", parsed.pretty_print());
56}Sourcepub fn extended_summary(&self) -> Option<TextBlock<'a>>
pub fn extended_summary(&self) -> Option<TextBlock<'a>>
Extended summary block, if present.
Sourcepub fn directives(&self) -> impl Iterator<Item = Directive<'a>>
pub fn directives(&self) -> impl Iterator<Item = Directive<'a>>
Iterate over document-level directives (e.g. .. deprecated:: 1.0).
Sourcepub fn sections(&self) -> impl Iterator<Item = Section<'a>>
pub fn sections(&self) -> impl Iterator<Item = Section<'a>>
Iterate over all sections, in source order.
Sourcepub fn paragraphs(&self) -> impl Iterator<Item = TextBlock<'a>>
pub fn paragraphs(&self) -> impl Iterator<Item = TextBlock<'a>>
Iterate over stray-prose paragraph blocks (PARAGRAPH nodes) between
sections, in source order.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Document<'a>
impl<'a> RefUnwindSafe for Document<'a>
impl<'a> Send for Document<'a>
impl<'a> Sync for Document<'a>
impl<'a> Unpin for Document<'a>
impl<'a> UnsafeUnpin for Document<'a>
impl<'a> UnwindSafe for Document<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more