Skip to content

Commit

Permalink
Make all serialization functions available for no-std
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom committed Apr 15, 2024
1 parent 2e15e3d commit 8e5cbb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/io/core.rs
Expand Up @@ -5,10 +5,13 @@ use alloc::vec::Vec;
use core::fmt::{self, Display};
use core::result;

/// see [`std::io::ErrorKind`]
pub enum ErrorKind {
/// see [`std::io::ErrorKind::Other`]
Other,
}

/// see [`std::io::Error`]
// I/O errors can never occur in no-std mode. All our no-std I/O implementations
// are infallible.
pub struct Error;
Expand All @@ -25,11 +28,15 @@ impl Error {
}
}

/// see [`std::io::Result`]
pub type Result<T> = result::Result<T, Error>;

/// see [`std::io::Write`]
pub trait Write {
/// see [`std::io::Write::write`]
fn write(&mut self, buf: &[u8]) -> Result<usize>;

/// see [`std::io::Write::write_all`]
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.
Expand All @@ -39,6 +46,7 @@ pub trait Write {
Ok(())
}

/// see [`std::io::Write::flush`]
fn flush(&mut self) -> Result<()>;
}

Expand Down
12 changes: 2 additions & 10 deletions src/lib.rs
Expand Up @@ -377,11 +377,7 @@ pub use crate::de::{from_slice, from_str, Deserializer, StreamDeserializer};
#[doc(inline)]
pub use crate::error::{Error, Result};
#[doc(inline)]
pub use crate::ser::{to_string, to_string_pretty, to_vec, to_vec_pretty};
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[doc(inline)]
pub use crate::ser::{to_writer, to_writer_pretty, Serializer};
pub use crate::ser::{to_string, to_string_pretty, to_vec, to_vec_pretty, to_writer, to_writer_pretty, Serializer};
#[doc(inline)]
pub use crate::value::{from_value, to_value, Map, Number, Value};

Expand All @@ -402,16 +398,12 @@ mod macros;
pub mod de;
pub mod error;
pub mod map;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod ser;
#[cfg(not(feature = "std"))]
mod ser;
pub mod value;

mod features_check;

mod io;
pub mod io;
#[cfg(feature = "std")]
mod iter;
#[cfg(feature = "float_roundtrip")]
Expand Down

0 comments on commit 8e5cbb8

Please sign in to comment.