Skip to content

Commit 1dd57a4

Browse files
authored
feat: replace write feature with std feature (#356)
* feat: replace `write` feature with `std` feature This also implements `std::error::Error` on `CollectionAllocErr` * docs: describe `std` feature
1 parent c83d633 commit 1dd57a4

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ readme = "README.md"
1313
documentation = "https://docs.rs/smallvec/"
1414

1515
[features]
16-
write = []
16+
std = []
1717
specialization = []
1818
may_dangle = []
1919
extract_if = []

src/lib.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@
1616
//!
1717
//! ## Optional features
1818
//!
19-
//! ### `serde`
19+
//! ### `std`
2020
//!
21-
//! When this optional dependency is enabled, `SmallVec` implements the `serde::Serialize` and
22-
//! `serde::Deserialize` traits.
21+
//! When this feature is enabled, traits available from `std` are implemented:
2322
//!
24-
//! ### `write`
23+
//! * `SmallVec<u8, _>` implements the [`std::io::Write`] trait.
24+
//! * [`CollectionAllocErr`] implements [`std::error::Error`].
2525
//!
26-
//! When this feature is enabled, `SmallVec<u8, _>` implements the `std::io::Write` trait.
2726
//! This feature is not compatible with `#![no_std]` programs.
2827
//!
28+
//! ### `serde`
29+
//!
30+
//! When this optional dependency is enabled, `SmallVec` implements the `serde::Serialize` and
31+
//! `serde::Deserialize` traits.
32+
//!
2933
//! ### `extract_if`
3034
//!
3135
//! **This feature is unstable.** It may change to match the unstable `extract_if` method in libstd.
@@ -62,7 +66,7 @@
6266
#[doc(hidden)]
6367
pub extern crate alloc;
6468

65-
#[cfg(any(test, feature = "write"))]
69+
#[cfg(any(test, feature = "std"))]
6670
extern crate std;
6771

6872
#[cfg(test)]
@@ -93,7 +97,7 @@ use serde::{
9397
de::{Deserialize, Deserializer, SeqAccess, Visitor},
9498
ser::{Serialize, SerializeSeq, Serializer},
9599
};
96-
#[cfg(feature = "write")]
100+
#[cfg(feature = "std")]
97101
use std::io;
98102

99103
/// Error type for APIs with fallible heap allocation
@@ -113,6 +117,10 @@ impl core::fmt::Display for CollectionAllocErr {
113117
}
114118
}
115119

120+
#[cfg(feature = "std")]
121+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
122+
impl std::error::Error for CollectionAllocErr {}
123+
116124
/// Either a stack array with `length <= N` or a heap array
117125
/// whose pointer and capacity are stored here.
118126
///
@@ -797,7 +805,7 @@ impl<T, const N: usize> SmallVec<T, N> {
797805
/// the elements `[0, at)` with its previous capacity unchanged.
798806
///
799807
/// - If you want to take ownership of the entire contents and capacity of
800-
/// the vector, see [`mem::take`] or [`mem::replace`].
808+
/// the vector, see [`core::mem::take`] or [`core::mem::replace`].
801809
/// - If you don't need the returned vector at all, see [`SmallVec::truncate`].
802810
/// - If you want to take ownership of an arbitrary subslice, or you don't
803811
/// necessarily want to store the removed items in a vector, see [`SmallVec::drain`].
@@ -2145,8 +2153,8 @@ where
21452153
}
21462154
}
21472155

2148-
#[cfg(feature = "write")]
2149-
#[cfg_attr(docsrs, doc(cfg(feature = "write")))]
2156+
#[cfg(feature = "std")]
2157+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
21502158
impl<const N: usize> io::Write for SmallVec<u8, N> {
21512159
#[inline]
21522160
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {

src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ fn test_resize() {
924924
assert_eq!(v[..], [1, 0][..]);
925925
}
926926

927-
#[cfg(feature = "write")]
927+
#[cfg(feature = "std")]
928928
#[test]
929929
fn test_write() {
930930
use std::io::Write;

0 commit comments

Comments
 (0)