Skip to main content

load_comments

Function load_comments 

Source
pub fn load_comments(input: &str) -> Result<Vec<Comment>>
Expand description

Scan a YAML document and return the list of comments it contains.

The source is driven through the event parser so the returned positions stay consistent with the spans on Spanned<T>. Comments are returned in source order.

§Errors

Returns an error if the input is not a lexically valid YAML document — e.g. an unclosed flow collection. Comments inside an otherwise-well-formed document are captured even if deeper parse stages (e.g. merge resolution) would later fail.

§Examples

use noyalib::{load_comments, CommentKind};
let yaml = "name: noyalib  # the library\n# trailing\n";
let comments = load_comments(yaml).unwrap();
assert_eq!(comments.len(), 2);
assert_eq!(comments[0].kind, CommentKind::Inline);
assert_eq!(comments[1].kind, CommentKind::Line);