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

Use stable features where possible #17

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features
args: --tests --no-default-features
- name: Run tests (std)
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features std
args: --tests --no-default-features --features std
- name: Run tests (alloc)
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features alloc
args: --tests --no-default-features --features alloc
test-msrv:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [1.47]
rust: [1.55]
steps:
- uses: actions/checkout@v2
- name: Install Rust toolchain
Expand All @@ -78,14 +78,14 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features
args: --tests --no-default-features
- name: Run tests (std)
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features std
args: --tests --no-default-features --features std
- name: Run tests (alloc)
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features alloc
args: --tests --no-default-features --features alloc
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Actions Status](https://github.com/bbqsrc/core2/workflows/CI/badge.svg)](https://github.com/bbqsrc/core2/actions)
[![Documentation](https://docs.rs/core2/badge.svg)](https://docs.rs/core2)
![Minimum Supported Rust Version (MSRV)](https://img.shields.io/badge/rust-v1.47.0+-blue)
![Minimum Supported Rust Version (MSRV)](https://img.shields.io/badge/rust-v1.55.0+-blue)

Ever wanted a `Cursor` or the `Error` trait in `no_std`? Well now you can have it. A 'fork' of Rust's `std` modules for `no_std` environments, with the added benefit of optionally taking advantage of `alloc`.

Expand All @@ -29,20 +29,19 @@ use `core2::error::Error` in place of `std::error::Error`.

- **std**: enables `std` pass-throughs for the polyfilled types, but allows accessing the new types
- **alloc**: enable aspects of the `Read` and `Write` traits that require `alloc` support (WIP)
- **nightly**: enables **nightly**-only features, such as `BufReader` and `BufWriter` with const generic buffers.
- **nightly**: enables **nightly**-only features

### Differences to `std::io`

- No `std::io::Error`, so we have our own copy without any `Os` error functions
- `IoSlice` and the `*_vectored` family of functions are not implemented.
- `BufReader` and `BufWriter` have a different signature, as they now use a const generic bounded array for the internal buffer. (Requires **nightly** feature)
- `BufReader` and `BufWriter` have a different signature, as they now use a const generic bounded array for the internal buffer.

Other than items perhaps being entirely missing or certain functions unavailable on some traits, no function signatures have been changed.

### Limitations

- Using the buffer types currently requires **nightly** due to the use of const generics.
- Using `copy` or the buffer types with `std` support currently requires **nightly** due to the `initializer` API.
- The `Error` implementation for the never type currently requires **nightly**.

## Where is it used?

Expand Down
3 changes: 0 additions & 3 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "nightly")]
mod buffered;
mod cursor;
mod error;
Expand All @@ -19,8 +18,6 @@ pub use std::io::{
};

// 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;
14 changes: 0 additions & 14 deletions src/io/util.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#[cfg(feature = "nightly")]
use core::mem::MaybeUninit;

#[cfg(feature = "nightly")]
use crate::io::{ErrorKind, Read, Write};

#[cfg(feature = "nightly")]
pub fn copy<R: ?Sized, W: ?Sized, const S: usize>(
reader: &mut R,
writer: &mut W,
Expand All @@ -14,17 +11,6 @@ where
W: Write,
{
let mut buf = MaybeUninit::<[u8; S]>::uninit();
// FIXME: #42788
//
// - This creates a (mut) reference to a slice of
// _uninitialized_ integers, which is **undefined behavior**
//
// - Only the standard library gets to soundly "ignore" this,
// based on its privileged knowledge of unstable rustc
// internals;
unsafe {
reader.initializer().initialize(buf.assume_init_mut());
}

let mut written = 0;
loop {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![cfg_attr(feature = "nightly", feature(maybe_uninit_ref))]
#![cfg_attr(feature = "nightly", feature(never_type))]
#![cfg_attr(all(feature = "std", feature = "nightly"), feature(read_initializer))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "std", allow(dead_code))]

Expand Down