Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Tidy up code style
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed May 18, 2024
1 parent 504c8ca commit 3c9336e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
11 changes: 1 addition & 10 deletions src/io/core.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//! Copy from [serde-rs/json](https://github.com/serde-rs/json/blob/207a57b68880769c81d525f9f5b38d3be1340806/src/io/core.rs)
//! Reimplements core logic and types from `std::io` in an `alloc`-friendly
//! fashion.
use alloc::vec::Vec;
use core::fmt::{self, Display};
use core::result;
Expand All @@ -11,8 +6,6 @@ pub enum ErrorKind {
Other,
}

// I/O errors can never occur in no-std mode. All our no-std I/O implementations
// are infallible.
pub struct Error;

impl Display for Error {
Expand All @@ -33,8 +26,6 @@ pub trait Write {
fn write(&mut self, buf: &[u8]) -> Result<usize>;

fn write_all(&mut self, buf: &[u8]) -> Result<()> {
// All our Write impls in no_std mode always write the whole buffer in
// one call infallibly.
let result = self.write(buf);
debug_assert!(result.is_ok());
debug_assert_eq!(result.unwrap_or(0), buf.len());
Expand Down Expand Up @@ -78,4 +69,4 @@ impl Write for Vec<u8> {
fn flush(&mut self) -> Result<()> {
Ok(())
}
}
}
17 changes: 3 additions & 14 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
//! Copy from [serde-rs/json](https://github.com/serde-rs/json/blob/0de7b516f504b5c1df1774425eef18efb132ed93/src/io/mod.rs)
//! A tiny, `no_std`-friendly facade around `std::io`.
//! Reexports types from `std` when available; otherwise reimplements and
//! provides some of the core logic.
//!
//! The main reason that `std::io` hasn't found itself reexported as part of
//! the `core` crate is the `std::io::{Read, Write}` traits' reliance on
//! `std::io::Error`, which may contain internally a heap-allocated `Box<Error>`
//! and/or now relying on OS-specific `std::backtrace::Backtrace`.
pub use self::imp::{Result, Write};
pub use self::io::{Result, Write};

#[cfg(not(feature = "std"))]
#[path = "core.rs"]
mod imp;
mod io;

#[cfg(feature = "std")]
use std::io as imp;
use std::io;
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

extern crate alloc;

pub use crate::de::{Deserializer, from_slice, from_str};
pub use crate::de::{from_slice, from_str, Deserializer};
pub use crate::error::{Error, Result};
pub use crate::ser::{Serializer, to_string, to_vec, to_writer};
pub use crate::ser::{to_string, to_vec, to_writer, Serializer};

mod de;
mod error;
mod io;
mod read;
mod ser;
mod io;

0 comments on commit 3c9336e

Please sign in to comment.