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.
The input is held to the default ParserConfig
limits a value parse would apply: at most max_document_length
bytes, and a pending key may hold back no more tokens than
max_events allows.
§Errors
Returns an error if the input is longer than the default
max_document_length, if a pending key holds back more tokens than
the default max_events allows, or 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);