-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor streaming JSON to separate modules
- Loading branch information
Showing
5 changed files
with
681 additions
and
649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use super::value::TryFromValueError; | ||
use core::fmt; | ||
|
||
/// JSON reader/writer error | ||
#[derive(Debug, PartialEq)] | ||
pub enum Error<E> { | ||
Io(E), | ||
Eof, | ||
Unexpected(char), | ||
NumberTooLarge, | ||
InvalidType, | ||
} | ||
|
||
impl<E: embedded_io_async::Error> From<E> for Error<E> { | ||
fn from(err: E) -> Self { | ||
Self::Io(err) | ||
} | ||
} | ||
|
||
impl<E> From<TryFromValueError> for Error<E> { | ||
fn from(_err: TryFromValueError) -> Self { | ||
Self::InvalidType | ||
} | ||
} | ||
|
||
impl<E: fmt::Display> fmt::Display for Error<E> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::Io(err) => write!(f, "I/O error: {err}"), | ||
Self::Eof => write!(f, "Premature EOF"), | ||
Self::Unexpected(ch) => write!(f, "Unexpected `{ch}`"), | ||
Self::NumberTooLarge => write!(f, "Number too large"), | ||
Self::InvalidType => write!(f, "Invalid type"), | ||
} | ||
} | ||
} | ||
|
||
impl<E> Error<E> { | ||
pub fn unexpected(ch: u8) -> Self { | ||
Self::Unexpected(char::from(ch)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![allow(unused_imports)] | ||
|
||
mod error; | ||
pub use self::error::Error; | ||
|
||
mod reader; | ||
pub use self::reader::{FromJson, Reader}; | ||
|
||
mod value; | ||
pub use self::value::{TryFromValueError, Value}; | ||
|
||
mod writer; | ||
pub use self::writer::{ObjectWriter, ToJson, Writer}; |
Oops, something went wrong.