io: Enable alloc from std

It is less surprising if the "alloc" feature is enabled from the "std"
feature.

Enable "alloc" in "std" and simplify the feature gating.
This commit is contained in:
Tobin C. Harding 2024-01-30 09:50:18 +11:00
parent ba1166a63b
commit 0997382772
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 7 additions and 4 deletions

View File

@ -15,7 +15,7 @@ exclude = ["tests", "contrib"]
[features] [features]
default = ["std"] default = ["std"]
std = [] std = ["alloc"]
alloc = [] alloc = []
[package.metadata.docs.rs] [package.metadata.docs.rs]

View File

@ -20,7 +20,7 @@
#![allow(clippy::needless_question_mark)] // https://github.com/rust-bitcoin/rust-bitcoin/pull/2134 #![allow(clippy::needless_question_mark)] // https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
#![allow(clippy::manual_range_contains)] // More readable than clippy's format. #![allow(clippy::manual_range_contains)] // More readable than clippy's format.
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(feature = "alloc")]
extern crate alloc; extern crate alloc;
mod error; mod error;
@ -316,6 +316,9 @@ pub fn sink() -> Sink { Sink }
mod tests { mod tests {
use super::*; use super::*;
#[cfg(feature = "alloc")]
use alloc::{string::ToString, vec};
#[test] #[test]
fn buf_read_fill_and_consume_slice() { fn buf_read_fill_and_consume_slice() {
let data = [0_u8, 1, 2]; let data = [0_u8, 1, 2];
@ -339,7 +342,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(feature = "alloc")]
fn read_to_limit_greater_than_total_length() { fn read_to_limit_greater_than_total_length() {
let s = "16-byte-string!!".to_string(); let s = "16-byte-string!!".to_string();
let mut reader = Cursor::new(&s); let mut reader = Cursor::new(&s);
@ -352,7 +355,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(feature = "alloc")]
fn read_to_limit_less_than_total_length() { fn read_to_limit_less_than_total_length() {
let s = "16-byte-string!!".to_string(); let s = "16-byte-string!!".to_string();
let mut reader = Cursor::new(&s); let mut reader = Cursor::new(&s);