pub fn extract(content: &str) -> Result<(Frontmatter, &str)>
Expand description
Extracts and parses frontmatter from content with format auto-detection.
This function provides zero-copy extraction of frontmatter where possible, automatically detecting the format (YAML, TOML, or JSON) and parsing it into a structured representation.
§Security
This function includes several security measures:
- Input validation and size limits
- Safe string handling
- Protection against malicious content
§Performance
Optimized for performance with:
- Zero-copy operations where possible
- Single-pass parsing
- Minimal allocations
- Pre-allocated buffers
§Examples
use frontmatter_gen::extract;
let content = r#"---
title: My Post
date: 2025-09-09
---
Content here"#;
let (frontmatter, content) = extract(content)?;
assert_eq!(frontmatter.get("title").unwrap().as_str().unwrap(), "My Post");
assert_eq!(content.trim(), "Content here");
§Errors
Returns Error
if:
- Content exceeds size limits
- Content is malformed
- Frontmatter format is invalid
- Parsing fails