diff --git a/Cargo.toml b/Cargo.toml index c3cc88c..bce2697 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" documentation = "https://docs.rs/smallvec/" [features] -write = [] +std = [] specialization = [] may_dangle = [] extract_if = [] diff --git a/src/lib.rs b/src/lib.rs index da61d95..c044c67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,16 +16,20 @@ //! //! ## Optional features //! -//! ### `serde` +//! ### `std` //! -//! When this optional dependency is enabled, `SmallVec` implements the `serde::Serialize` and -//! `serde::Deserialize` traits. +//! When this feature is enabled, traits available from `std` are implemented: //! -//! ### `write` +//! * `SmallVec` implements the [`std::io::Write`] trait. +//! * [`CollectionAllocErr`] implements [`std::error::Error`]. //! -//! When this feature is enabled, `SmallVec` implements the `std::io::Write` trait. //! This feature is not compatible with `#![no_std]` programs. //! +//! ### `serde` +//! +//! When this optional dependency is enabled, `SmallVec` implements the `serde::Serialize` and +//! `serde::Deserialize` traits. +//! //! ### `extract_if` //! //! **This feature is unstable.** It may change to match the unstable `extract_if` method in libstd. @@ -62,7 +66,7 @@ #[doc(hidden)] pub extern crate alloc; -#[cfg(any(test, feature = "write"))] +#[cfg(any(test, feature = "std"))] extern crate std; #[cfg(test)] @@ -93,7 +97,7 @@ use serde::{ de::{Deserialize, Deserializer, SeqAccess, Visitor}, ser::{Serialize, SerializeSeq, Serializer}, }; -#[cfg(feature = "write")] +#[cfg(feature = "std")] use std::io; /// Error type for APIs with fallible heap allocation @@ -113,6 +117,10 @@ impl core::fmt::Display for CollectionAllocErr { } } +#[cfg(feature = "std")] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] +impl std::error::Error for CollectionAllocErr {} + /// Either a stack array with `length <= N` or a heap array /// whose pointer and capacity are stored here. /// @@ -797,7 +805,7 @@ impl SmallVec { /// the elements `[0, at)` with its previous capacity unchanged. /// /// - If you want to take ownership of the entire contents and capacity of - /// the vector, see [`mem::take`] or [`mem::replace`]. + /// the vector, see [`core::mem::take`] or [`core::mem::replace`]. /// - If you don't need the returned vector at all, see [`SmallVec::truncate`]. /// - If you want to take ownership of an arbitrary subslice, or you don't /// necessarily want to store the removed items in a vector, see [`SmallVec::drain`]. @@ -2145,8 +2153,8 @@ where } } -#[cfg(feature = "write")] -#[cfg_attr(docsrs, doc(cfg(feature = "write")))] +#[cfg(feature = "std")] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl io::Write for SmallVec { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { diff --git a/src/tests.rs b/src/tests.rs index 133d593..3186fb5 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -924,7 +924,7 @@ fn test_resize() { assert_eq!(v[..], [1, 0][..]); } -#[cfg(feature = "write")] +#[cfg(feature = "std")] #[test] fn test_write() { use std::io::Write;