Skip to main content

Parse

Trait Parse 

Source
pub trait Parse: Sized {
Show 13 methods // Required method fn parse_in<C, E>( parser: &mut Parser<C, E>, context: Context, ) -> Result<(Self, usize), Error<E>> where C: Iterator<Item = Result<DecodedChar, E>>; // Provided methods fn parse_slice(content: &[u8]) -> Result<(Self, CodeMap), Error> { ... } fn parse_slice_with( content: &[u8], options: Options, ) -> Result<(Self, CodeMap), Error> { ... } fn parse_str(content: &str) -> Result<(Self, CodeMap), Error> { ... } fn parse_str_with( content: &str, options: Options, ) -> Result<(Self, CodeMap), Error> { ... } fn parse_infallible_utf8<C>(chars: C) -> Result<(Self, CodeMap), Error> where C: Iterator<Item = char> { ... } fn parse_utf8_infallible_with<C>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error> where C: Iterator<Item = char> { ... } fn parse_utf8<C, E>(chars: C) -> Result<(Self, CodeMap), Error<E>> where C: Iterator<Item = Result<char, E>> { ... } fn parse_utf8_with<C, E>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error<E>> where C: Iterator<Item = Result<char, E>> { ... } fn parse_infallible<C>(chars: C) -> Result<(Self, CodeMap), Error> where C: Iterator<Item = DecodedChar> { ... } fn parse_infallible_with<C>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error> where C: Iterator<Item = DecodedChar> { ... } fn parse<C, E>(chars: C) -> Result<(Self, CodeMap), Error<E>> where C: Iterator<Item = Result<DecodedChar, E>> { ... } fn parse_with<C, E>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error<E>> where C: Iterator<Item = Result<DecodedChar, E>> { ... }
}
Expand description

JSON parsing methods.

Every method returns the parsed value together with the CodeMap describing where each of its fragments came from.

§Example

use jstrict::{Parse, Value};

let (value, code_map) = Value::parse_str("[1, 2]")?;
assert_eq!(code_map.len(), 3); // the array and its two items.

Required Methods§

Source

fn parse_in<C, E>( parser: &mut Parser<C, E>, context: Context, ) -> Result<(Self, usize), Error<E>>
where C: Iterator<Item = Result<DecodedChar, E>>,

Parses a value in the middle of an ongoing parse, using parser and the surrounding Context.

Returns the value along with the index of its code map fragment. This is the single method implementors must provide; everything else is a wrapper around it.

§Errors

Returns Error::Stream if the character stream yields an error, or another Error variant if the input is not well-formed JSON.

Provided Methods§

Source

fn parse_slice(content: &[u8]) -> Result<(Self, CodeMap), Error>

Parses a value from a UTF-8 byte slice.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse_slice_with( content: &[u8], options: Options, ) -> Result<(Self, CodeMap), Error>

Parses a value from a UTF-8 byte slice, with the given options.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse_str(content: &str) -> Result<(Self, CodeMap), Error>

Parses a value from a string.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse_str_with( content: &str, options: Options, ) -> Result<(Self, CodeMap), Error>

Parses a value from a string, with the given options.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse_infallible_utf8<C>(chars: C) -> Result<(Self, CodeMap), Error>
where C: Iterator<Item = char>,

Parses a value from an infallible iterator of UTF-8 characters.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse_utf8_infallible_with<C>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error>
where C: Iterator<Item = char>,

Parses a value from an infallible iterator of UTF-8 characters, with the given options.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse_utf8<C, E>(chars: C) -> Result<(Self, CodeMap), Error<E>>
where C: Iterator<Item = Result<char, E>>,

Parses a value from a fallible iterator of UTF-8 characters.

Stream errors of type E are wrapped in Error::Stream.

§Errors

Returns Error::Stream if the character stream yields an error, or another Error variant if the input is not well-formed JSON.

Source

fn parse_utf8_with<C, E>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error<E>>
where C: Iterator<Item = Result<char, E>>,

Parses a value from a fallible iterator of UTF-8 characters, with the given options.

§Errors

Returns Error::Stream if the character stream yields an error, or another Error variant if the input is not well-formed JSON.

Source

fn parse_infallible<C>(chars: C) -> Result<(Self, CodeMap), Error>
where C: Iterator<Item = DecodedChar>,

Parses a value from an infallible iterator of decoded characters.

Unlike the utf8 variants, DecodedChar carries the byte length of each character in the source encoding, so spans stay accurate when the input is not UTF-8.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse_infallible_with<C>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error>
where C: Iterator<Item = DecodedChar>,

Parses a value from an infallible iterator of decoded characters, with the given options.

§Errors

Returns an Error if the input is not well-formed JSON.

Source

fn parse<C, E>(chars: C) -> Result<(Self, CodeMap), Error<E>>
where C: Iterator<Item = Result<DecodedChar, E>>,

Parses a value from a fallible iterator of decoded characters.

§Errors

Returns Error::Stream if the character stream yields an error, or another Error variant if the input is not well-formed JSON.

Source

fn parse_with<C, E>( chars: C, options: Options, ) -> Result<(Self, CodeMap), Error<E>>
where C: Iterator<Item = Result<DecodedChar, E>>,

Parses a value from a fallible iterator of decoded characters, with the given options.

§Errors

Returns Error::Stream if the character stream yields an error, or another Error variant if the input is not well-formed JSON.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Parse for ()

Source§

fn parse_in<C, E>( parser: &mut Parser<C, E>, _context: Context, ) -> Result<((), usize), Error<E>>
where C: Iterator<Item = Result<DecodedChar, E>>,

Source§

impl Parse for CompactString

Source§

fn parse_in<C, E>( parser: &mut Parser<C, E>, _context: Context, ) -> Result<(CompactString, usize), Error<E>>
where C: Iterator<Item = Result<DecodedChar, E>>,

Source§

impl Parse for bool

Source§

fn parse_in<C, E>( parser: &mut Parser<C, E>, _context: Context, ) -> Result<(bool, usize), Error<E>>
where C: Iterator<Item = Result<DecodedChar, E>>,

Implementors§