#compat #const-generics #no-alloc #embedded #polyfill #byte-buffer #match

no-std core2

The bare essentials of std::io for use in no_std. Alloc support is optional.

7 releases

0.4.0 Jan 29, 2022
0.3.3 Jan 18, 2022
0.3.2 Sep 28, 2021
0.3.1 Jul 5, 2021
0.0.0 Feb 13, 2021

#14 in No standard library

Download history 109415/week @ 2023-10-18 110230/week @ 2023-10-25 107032/week @ 2023-11-01 114290/week @ 2023-11-08 131455/week @ 2023-11-15 111630/week @ 2023-11-22 122913/week @ 2023-11-29 113355/week @ 2023-12-06 105667/week @ 2023-12-13 82411/week @ 2023-12-20 65168/week @ 2023-12-27 104164/week @ 2024-01-03 115292/week @ 2024-01-10 123855/week @ 2024-01-17 125407/week @ 2024-01-24 97147/week @ 2024-01-31

481,781 downloads per month
Used in 862 crates (39 directly)

Apache-2.0 OR MIT

130KB
1.5K SLoC

core2

Actions Status Documentation Minimum Supported Rust Version (MSRV)

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.

The goal of this crate is to provide a stable interface for building I/O and error trait functionality in no_std environments. The current code corresponds to the most recent stable API of Rust 1.47.0. It is also a goal to achieve a true alloc-less experience, with opt-in alloc support.

This crate works on stable with some limitations in functionality, and nightly without limitations by adding the relevant feature flag.

This crate is std by default -- use no default features to get no_std mode.

Usage

[dependencies]
core2 = "0.3"

Add the crate, use the things you would usually want from std::io, but instead from core2::io, and use core2::error::Error in place of std::error::Error.

Features

  • 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.

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)

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.

Where is it used?

All of the below are works in progress, but should help with demonstrating how to use this crate.

License

Licensed under either of

at your option.


Almost all of the code in this repository is a copy of the Rust language codebase with minor modifications.

For attributions, see https://thanks.rust-lang.org/.

Dependencies

~175–315KB