INNER CODE UNIT · Rust
parse
ShurikenTrade/shuriken-skills · src/frontmatter.rs:23
pub fn parse(raw: &str) -> Result<Parsed<'_>, String> {
let matter = Matter::<YAML>::new();
let parsed = matter.parse(raw);
let data = parsed
.data
.ok_or_else(|| "missing frontmatter block".to_string())?;
let frontmatter: Frontmatter = data
.deserialize()
.map_err(|e| format!("invalid frontmatter: {e}"))?;
if !raw.starts_with("---") {
return Err("missing frontmatter block".to_string());
}
// gray_matter has already validated the frontmatter block; the closing `---`
// must be present for `data` to have been Some. Locate the end of the