From 3c950bc054d143fb05a859711e6d98f01317af9d Mon Sep 17 00:00:00 2001 From: Brendan Molloy Date: Sat, 13 Feb 2021 19:02:46 +0100 Subject: [PATCH] Move io into module --- .github/workflows/ci.yml | 11 ++++++----- Cargo.toml | 11 +++++------ src/{ => io}/buffered.rs | 2 +- src/{ => io}/cursor.rs | 2 +- src/{ => io}/error.rs | 0 src/{ => io}/impls.rs | 4 ++-- src/io/mod.rs | 26 ++++++++++++++++++++++++++ src/{ => io}/traits.rs | 0 src/{ => io}/util.rs | 4 ++-- src/lib.rs | 28 ++-------------------------- tests/tests.rs | 2 +- 11 files changed, 46 insertions(+), 44 deletions(-) rename src/{ => io}/buffered.rs (99%) rename src/{ => io}/cursor.rs (99%) rename src/{ => io}/error.rs (100%) rename src/{ => io}/impls.rs (97%) create mode 100644 src/io/mod.rs rename src/{ => io}/traits.rs (100%) rename src/{ => io}/util.rs (94%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e472ba..1da3fda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,17 +20,17 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --tests --features nightly + args: --tests --no-default-features --features nightly - name: Run tests (std) uses: actions-rs/cargo@v1 with: command: test - args: --tests --features std-nightly + args: --tests --no-default-features --features std,nightly - name: Run tests (alloc) uses: actions-rs/cargo@v1 with: command: test - args: --tests --features nightly,alloc + args: --tests --no-default-features --features alloc,nightly test-stable: runs-on: ${{ matrix.os }} strategy: @@ -49,13 +49,14 @@ jobs: uses: actions-rs/cargo@v1 with: command: test + args: --no-default-features - name: Run tests (std) uses: actions-rs/cargo@v1 with: command: test - args: --features std + args: --no-default-features --features std - name: Run tests (alloc) uses: actions-rs/cargo@v1 with: command: test - args: --features alloc \ No newline at end of file + args: --no-default-features --features alloc \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 478752d..6c874bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,22 +1,21 @@ [package] -name = "bare-io" -version = "0.2.1" +name = "core2" +version = "0.1.0" authors = ["Brendan Molloy "] description = "The bare essentials of std::io for use in no_std. Alloc support is optional." license = "Apache-2.0 OR MIT" edition = "2018" -repository = "https://github.com/bbqsrc/bare-io" +repository = "https://github.com/bbqsrc/core2" categories = ["no-std"] [dependencies] memchr = { version = "2", default-features = false } [features] -default = [] -alloc = [] +default = ["std"] std = ["alloc"] +alloc = [] nightly = [] -std-nightly = ["std", "nightly"] [package.metadata.docs.rs] features = ["nightly"] diff --git a/src/buffered.rs b/src/io/buffered.rs similarity index 99% rename from src/buffered.rs rename to src/io/buffered.rs index 4b3241a..38b648d 100644 --- a/src/buffered.rs +++ b/src/io/buffered.rs @@ -1,6 +1,6 @@ //! Buffering wrappers for I/O traits -use crate::{BufRead, Error, ErrorKind, Read, Result, Seek, SeekFrom, Write}; +use crate::io::{BufRead, Error, ErrorKind, Read, Result, Seek, SeekFrom, Write}; use core::{cmp, fmt}; /// The `BufReader` struct adds buffering to any reader. diff --git a/src/cursor.rs b/src/io/cursor.rs similarity index 99% rename from src/cursor.rs rename to src/io/cursor.rs index 8fdd3d9..93bd728 100644 --- a/src/cursor.rs +++ b/src/io/cursor.rs @@ -1,4 +1,4 @@ -use crate::{BufRead, Error, ErrorKind, Read, Result, Seek, SeekFrom, Write}; +use super::{BufRead, Error, ErrorKind, Read, Result, Seek, SeekFrom, Write}; use core::cmp; /// A `Cursor` wraps an in-memory buffer and provides it with a diff --git a/src/error.rs b/src/io/error.rs similarity index 100% rename from src/error.rs rename to src/io/error.rs diff --git a/src/impls.rs b/src/io/impls.rs similarity index 97% rename from src/impls.rs rename to src/io/impls.rs index d38ad30..e783ede 100644 --- a/src/impls.rs +++ b/src/io/impls.rs @@ -1,5 +1,5 @@ -use crate::error::{Error, ErrorKind, Result}; -use crate::traits::{BufRead, Read, Seek, SeekFrom, Write}; +use super::error::{Error, ErrorKind, Result}; +use super::traits::{BufRead, Read, Seek, SeekFrom, Write}; use core::{cmp, fmt, mem}; // ============================================================================= diff --git a/src/io/mod.rs b/src/io/mod.rs new file mode 100644 index 0000000..988c0cb --- /dev/null +++ b/src/io/mod.rs @@ -0,0 +1,26 @@ +#[cfg(feature = "nightly")] +mod buffered; +mod cursor; +mod error; +mod impls; +mod traits; +mod util; + +#[cfg(not(feature = "std"))] +pub use cursor::Cursor; +#[cfg(not(feature = "std"))] +pub use error::{Error, ErrorKind, Result}; +#[cfg(not(feature = "std"))] +pub use traits::{BufRead, Bytes, Chain, Read, Seek, SeekFrom, Take, Write}; + +#[cfg(feature = "std")] +pub use std::io::{ + BufRead, Bytes, Chain, Cursor, Error, ErrorKind, Read, Result, Seek, SeekFrom, Take, Write, +}; + +// Use this crate's implementation on both std and no_std +#[cfg(feature = "nightly")] +pub use buffered::{BufReader, BufWriter, LineWriter}; + +#[cfg(feature = "nightly")] +pub use util::copy; diff --git a/src/traits.rs b/src/io/traits.rs similarity index 100% rename from src/traits.rs rename to src/io/traits.rs diff --git a/src/util.rs b/src/io/util.rs similarity index 94% rename from src/util.rs rename to src/io/util.rs index 6ecbd49..14ff286 100644 --- a/src/util.rs +++ b/src/io/util.rs @@ -2,13 +2,13 @@ use core::mem::MaybeUninit; #[cfg(feature = "nightly")] -use crate::{ErrorKind, Read, Write}; +use crate::io::{ErrorKind, Read, Write}; #[cfg(feature = "nightly")] pub fn copy( reader: &mut R, writer: &mut W, -) -> crate::Result +) -> crate::io::Result where R: Read, W: Write, diff --git a/src/lib.rs b/src/lib.rs index f6a1561..abce547 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,33 +2,9 @@ #![cfg_attr(feature = "nightly", feature(maybe_uninit_ref))] #![cfg_attr(all(feature = "std", feature = "nightly"), feature(read_initializer))] #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(feature = "std", allow(dead_code))] -#[cfg(feature = "nightly")] -mod buffered; -mod cursor; -mod error; -mod impls; -mod traits; -mod util; +pub mod io; #[cfg(feature = "alloc")] extern crate alloc; - -#[cfg(not(feature = "std"))] -pub use cursor::Cursor; -#[cfg(not(feature = "std"))] -pub use error::{Error, ErrorKind, Result}; -#[cfg(not(feature = "std"))] -pub use traits::{BufRead, Bytes, Chain, Read, Seek, SeekFrom, Take, Write}; - -#[cfg(feature = "std")] -pub use std::io::{ - BufRead, Bytes, Chain, Cursor, Error, ErrorKind, Read, Result, Seek, SeekFrom, Take, Write, -}; - -// Use this crate's implementation on both std and no_std -#[cfg(feature = "nightly")] -pub use buffered::{BufReader, BufWriter, LineWriter}; - -#[cfg(feature = "nightly")] -pub use util::copy; diff --git a/tests/tests.rs b/tests/tests.rs index 3cbb5b7..e72ee70 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,4 +1,4 @@ -use bare_io::{self as io, BufRead, Cursor, Read, Write}; +use core2::io::{self as io, BufRead, Cursor, Read, Write}; use core::cmp; // #[test]