pub struct ToonParser { /* private fields */ }Expand description
TOON-LD Parser
Parses TOON-LD format back to JSON/JSON-LD values. The parser handles:
- Indented key-value pairs
- Tabular arrays (CSV format with header)
- Primitive arrays (inline or multi-line)
- Quoted and unquoted string values
§Example
use toon_core::ToonParser;
let parser = ToonParser::new();
let toon = r#"
name: Alice
age: 30
"#;
let value = parser.parse(toon).unwrap();
assert_eq!(value.get("name").unwrap(), "Alice");
assert_eq!(value.get("age").unwrap(), 30);Implementations§
Source§impl ToonParser
impl ToonParser
Sourcepub fn new() -> ToonParser
pub fn new() -> ToonParser
Create a new parser with default settings.
§Example
use toon_core::ToonParser;
let parser = ToonParser::new();Sourcepub fn with_context(self, context: JsonLdContext) -> ToonParser
pub fn with_context(self, context: JsonLdContext) -> ToonParser
Sourcepub fn context(&self) -> &JsonLdContext
pub fn context(&self) -> &JsonLdContext
Get a reference to the current context.
Sourcepub fn parse(&self, input: &str) -> Result<Value, ToonError>
pub fn parse(&self, input: &str) -> Result<Value, ToonError>
Parse TOON-LD string to JSON value.
§Arguments
input- The TOON-LD string to parse
§Returns
A Result containing the parsed JSON value or an error.
§Example
use toon_core::ToonParser;
let parser = ToonParser::new();
let value = parser.parse("name: Alice\nage: 30").unwrap();
assert_eq!(value.get("name").unwrap(), "Alice");Sourcepub fn parse_to_json(&self, input: &str) -> Result<String, ToonError>
pub fn parse_to_json(&self, input: &str) -> Result<String, ToonError>
Parse TOON-LD string to pretty-printed JSON string.
§Arguments
input- The TOON-LD string to parse
§Returns
A Result containing the JSON string or an error.
§Example
use toon_core::ToonParser;
let parser = ToonParser::new();
let json = parser.parse_to_json("name: Alice").unwrap();
assert!(json.contains("\"name\""));
assert!(json.contains("\"Alice\""));Trait Implementations§
Source§impl Clone for ToonParser
impl Clone for ToonParser
Source§fn clone(&self) -> ToonParser
fn clone(&self) -> ToonParser
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ToonParser
impl Debug for ToonParser
Source§impl Default for ToonParser
impl Default for ToonParser
Source§fn default() -> ToonParser
fn default() -> ToonParser
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ToonParser
impl RefUnwindSafe for ToonParser
impl Send for ToonParser
impl Sync for ToonParser
impl Unpin for ToonParser
impl UnwindSafe for ToonParser
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