JSONParser

Struct JSONParser 

Source
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>

Source

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);
Source

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());
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.