Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all serialization functions available for no-std #1122

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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