pub struct JSONParser<'a> {
pub parser: Parser<'a>,
}Expand description
A JSON parser that can parse a JSON input string to a JSONValue.
§Example
use jsonparser::JSONParser;
let input = r#"
{
"name": "John Doe",
"age": 30
}
"#;
let mut parser = JSONParser::new(input);Fields§
§parser: Parser<'a>Implementations§
Source§impl<'a> JSONParser<'a>
impl<'a> JSONParser<'a>
Sourcepub fn new(input: &'a str) -> Self
pub fn new(input: &'a str) -> Self
Create a new JSONParser instance with the given input string.
§Example
use jsonparser::JSONParser;
let input = r#"
{
"name": "John Doe",
"age": 30
}
"#;
let mut parser = JSONParser::new(input);Sourcepub fn parse(&mut self) -> Result<JSONValue, String>
pub fn parse(&mut self) -> Result<JSONValue, String>
Parse the JSON input to a JSONValue.
§Example
use jsonparser::JSONParser;
let input = r#"
{
"name": "John Doe",
"age": 30
}
"#;
let mut parser = JSONParser::new(input);
let json = match parser.parse() {
Ok(value) => value,
Err(e) => {
eprintln!("Error: {}", e);
return;
}
};
println!("{:#?}", json["name"].as_str());Sourcepub fn from(input: &'a str) -> Result<JSONValue, String>
pub fn from(input: &'a str) -> Result<JSONValue, String>
Parse the JSON input to a JSONValue.
§Example
use jsonparser::JSONParser;
let input = r#"
{
"name": "John Doe",
"age": 30
}
"#;
let json = match JSONParser::from(input) {
Ok(value) => value,
Err(e) => {
eprintln!("Error: {}", e);
return;
}
};
println!("{:#?}", json["name"].as_str());Auto Trait Implementations§
impl<'a> Freeze for JSONParser<'a>
impl<'a> RefUnwindSafe for JSONParser<'a>
impl<'a> Send for JSONParser<'a>
impl<'a> Sync for JSONParser<'a>
impl<'a> Unpin for JSONParser<'a>
impl<'a> UnwindSafe for JSONParser<'a>
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