diff --git a/Cargo.toml b/Cargo.toml index 199e7c1..98d2c51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "managed" -version = "0.2.1" +version = "0.3.0" authors = ["whitequark "] description = "An interface for logically owning objects, whether or not heap allocation is available." documentation = "https://docs.rs/managed/" @@ -11,7 +11,7 @@ keywords = ["ownership"] license = "0BSD" [features] -use_std = [] -use_alloc = [] -use_collections = [] -default = ["use_std"] +std = [] +alloc = [] +collections = [] +default = ["std"] diff --git a/README.md b/README.md index 50714bb..29aab29 100644 --- a/README.md +++ b/README.md @@ -66,18 +66,18 @@ You probably want to disable default features and configure them one by one: managed = { version = "...", default-features = false, features = ["..."] } ``` -### Feature `use_std` +### Feature `std` -The `use_std` feature enables use of `Box` and `Vec` through a dependency on the `std` crate. +The `std` feature enables use of `Box` and `Vec` through a dependency on the `std` crate. -### Feature `use_alloc` +### Feature `alloc` -The `use_alloc` feature enables use of `Box` through a dependency on the `alloc` crate. +The `alloc` feature enables use of `Box` through a dependency on the `alloc` crate. This only works on nightly rustc. -### Feature `use_collections` +### Feature `collections` -The `use_collections` feature enables use of `Vec` through a dependency on +The `collections` feature enables use of `Vec` through a dependency on the `collections` crate. This only works on nightly rustc. Usage diff --git a/src/lib.rs b/src/lib.rs index c9e8825..dc82a34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,15 @@ #![no_std] -#![cfg_attr(all(feature = "use_alloc", not(feature = "use_std")), feature(alloc))] -#![cfg_attr(all(feature = "use_collections", not(feature = "use_std")), feature(collections))] +#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))] +#![cfg_attr(all(feature = "collections", not(feature = "std")), feature(collections))] //! A library that provides a way to logically own objects, whether or not //! heap allocation is available. -#[cfg(feature = "use_std")] +#[cfg(feature = "std")] extern crate std; -#[cfg(all(feature = "use_alloc", not(feature = "use_std")))] +#[cfg(all(feature = "alloc", not(feature = "std")))] extern crate alloc; -#[cfg(all(feature = "use_collections", not(feature = "use_std")))] +#[cfg(all(feature = "collections", not(feature = "std")))] extern crate collections; mod object; diff --git a/src/object.rs b/src/object.rs index 220b28f..c051247 100644 --- a/src/object.rs +++ b/src/object.rs @@ -1,13 +1,13 @@ use core::ops::{Deref, DerefMut}; use core::fmt; -#[cfg(feature = "use_std")] +#[cfg(feature = "std")] use std::boxed::Box; -#[cfg(all(feature = "use_alloc", not(feature = "use_std")))] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::boxed::Box; -#[cfg(feature = "use_std")] +#[cfg(feature = "std")] use std::vec::Vec; -#[cfg(all(feature = "use_alloc", feature = "use_collections", not(feature = "use_std")))] +#[cfg(all(feature = "alloc", feature = "collections", not(feature = "std")))] use collections::vec::Vec; /// A managed object. @@ -31,8 +31,8 @@ use collections::vec::Vec; pub enum Managed<'a, T: 'a + ?Sized> { /// Borrowed variant. Borrowed(&'a mut T), - /// Owned variant, only available with the `use_std` or `use_alloc` feature enabled. - #[cfg(any(feature = "use_std", feature = "use_alloc"))] + /// Owned variant, only available with the `std` or `alloc` feature enabled. + #[cfg(any(feature = "std", feature = "alloc"))] Owned(Box) } @@ -41,7 +41,7 @@ impl<'a, T: 'a + ?Sized> fmt::Debug for Managed<'a, T> fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { &Managed::Borrowed(ref x) => write!(f, "Borrowed({:?})", x), - #[cfg(any(feature = "use_std", feature = "use_alloc"))] + #[cfg(any(feature = "std", feature = "alloc"))] &Managed::Owned(ref x) => write!(f, "Owned({:?})", x) } @@ -54,14 +54,14 @@ impl<'a, T: 'a + ?Sized> From<&'a mut T> for Managed<'a, T> { } } -#[cfg(any(feature = "use_std", feature = "use_alloc"))] +#[cfg(any(feature = "std", feature = "alloc"))] impl From> for Managed<'static, T> { fn from(value: Box) -> Self { Managed::Owned(value) } } -#[cfg(any(feature = "use_std", all(feature = "use_alloc", feature = "use_collections")))] +#[cfg(any(feature = "std", all(feature = "alloc", feature = "collections")))] impl From> for Managed<'static, [T]> { fn from(value: Vec) -> Self { Managed::Owned(value.into_boxed_slice()) @@ -74,7 +74,7 @@ impl<'a, T: 'a + ?Sized> Deref for Managed<'a, T> { fn deref(&self) -> &Self::Target { match self { &Managed::Borrowed(ref value) => value, - #[cfg(any(feature = "use_std", feature = "use_alloc"))] + #[cfg(any(feature = "std", feature = "alloc"))] &Managed::Owned(ref value) => value } } @@ -84,7 +84,7 @@ impl<'a, T: 'a + ?Sized> DerefMut for Managed<'a, T> { fn deref_mut(&mut self) -> &mut Self::Target { match self { &mut Managed::Borrowed(ref mut value) => value, - #[cfg(any(feature = "use_std", feature = "use_alloc"))] + #[cfg(any(feature = "std", feature = "alloc"))] &mut Managed::Owned(ref mut value) => value } } diff --git a/src/slice.rs b/src/slice.rs index 3a095e1..6e2b506 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -1,13 +1,13 @@ use core::ops::{Deref, DerefMut}; use core::fmt; -#[cfg(feature = "use_std")] +#[cfg(feature = "std")] use std::boxed::Box; -#[cfg(all(feature = "use_alloc", not(feature = "use_std")))] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::boxed::Box; -#[cfg(feature = "use_std")] +#[cfg(feature = "std")] use std::vec::Vec; -#[cfg(all(feature = "use_collections", not(feature = "use_std")))] +#[cfg(all(feature = "collections", not(feature = "std")))] use collections::vec::Vec; /// A managed slice. @@ -29,8 +29,8 @@ use collections::vec::Vec; pub enum ManagedSlice<'a, T: 'a> { /// Borrowed variant. Borrowed(&'a mut [T]), - /// Owned variant, only available with the `use_std` or `use_collections` feature enabled. - #[cfg(any(feature = "use_std", feature = "use_collections"))] + /// Owned variant, only available with the `std` or `collections` feature enabled. + #[cfg(any(feature = "std", feature = "collections"))] Owned(Vec) } @@ -39,7 +39,7 @@ impl<'a, T: 'a> fmt::Debug for ManagedSlice<'a, T> fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { &ManagedSlice::Borrowed(ref x) => write!(f, "Borrowed({:?})", x), - #[cfg(any(feature = "use_std", feature = "use_collections"))] + #[cfg(any(feature = "std", feature = "collections"))] &ManagedSlice::Owned(ref x) => write!(f, "Owned({:?})", x) } @@ -67,11 +67,11 @@ macro_rules! from_unboxed_slice { ) } -#[cfg(any(feature = "use_std", all(feature = "use_alloc", feature = "use_collections")))] +#[cfg(any(feature = "std", all(feature = "alloc", feature = "collections")))] from_unboxed_slice!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31); -#[cfg(any(feature = "use_std", feature = "use_collections"))] +#[cfg(any(feature = "std", feature = "collections"))] impl From> for ManagedSlice<'static, T> { fn from(value: Vec) -> Self { ManagedSlice::Owned(value) @@ -84,7 +84,7 @@ impl<'a, T: 'a> Deref for ManagedSlice<'a, T> { fn deref(&self) -> &Self::Target { match self { &ManagedSlice::Borrowed(ref value) => value, - #[cfg(any(feature = "use_std", feature = "use_collections"))] + #[cfg(any(feature = "std", feature = "collections"))] &ManagedSlice::Owned(ref value) => value } } @@ -94,7 +94,7 @@ impl<'a, T: 'a> DerefMut for ManagedSlice<'a, T> { fn deref_mut(&mut self) -> &mut Self::Target { match self { &mut ManagedSlice::Borrowed(ref mut value) => value, - #[cfg(any(feature = "use_std", feature = "use_collections"))] + #[cfg(any(feature = "std", feature = "collections"))] &mut ManagedSlice::Owned(ref mut value) => value } }