The collections crate was merged into the alloc crate

This commit is contained in:
Philipp Oppermann 2017-09-08 10:34:24 +02:00 committed by whitequark
parent 21483da56b
commit 9db51c3194
6 changed files with 14 additions and 27 deletions

View File

@ -10,11 +10,7 @@ matrix:
- rust: nightly
env: FEATURES='alloc'
- rust: nightly
env: FEATURES='collections'
- rust: nightly
env: FEATURES='alloc collections'
- rust: nightly
env: FEATURES='std alloc collections'
env: FEATURES='std alloc'
script:
- cargo build --no-default-features --features "$FEATURES"
notifications:

View File

@ -14,5 +14,4 @@ license = "0BSD"
[features]
std = []
alloc = []
collections = []
default = ["std"]

View File

@ -72,14 +72,9 @@ The `std` feature enables use of `Box` and `Vec` through a dependency on the `st
### Feature `alloc`
The `alloc` feature enables use of `Box` through a dependency on the `alloc` crate.
The `alloc` feature enables use of `Box` and `Vec` through a dependency on the `alloc` crate.
This only works on nightly rustc.
### Feature `collections`
The `collections` feature enables use of `Vec` through a dependency on
the `collections` crate. This only works on nightly rustc.
Usage
-----

View File

@ -1,6 +1,5 @@
#![no_std]
#![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.
@ -9,8 +8,6 @@
extern crate std;
#[cfg(all(feature = "alloc", not(feature = "std")))]
extern crate alloc;
#[cfg(all(feature = "collections", not(feature = "std")))]
extern crate collections;
mod object;
mod slice;

View File

@ -7,8 +7,8 @@ use std::boxed::Box;
use alloc::boxed::Box;
#[cfg(feature = "std")]
use std::vec::Vec;
#[cfg(all(feature = "alloc", feature = "collections", not(feature = "std")))]
use collections::vec::Vec;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;
/// A managed object.
///
@ -61,7 +61,7 @@ impl<T: ?Sized + 'static> From<Box<T>> for Managed<'static, T> {
}
}
#[cfg(any(feature = "std", all(feature = "alloc", feature = "collections")))]
#[cfg(any(feature = "std", feature = "alloc"))]
impl<T: 'static> From<Vec<T>> for Managed<'static, [T]> {
fn from(value: Vec<T>) -> Self {
Managed::Owned(value.into_boxed_slice())

View File

@ -7,8 +7,8 @@ use std::boxed::Box;
use alloc::boxed::Box;
#[cfg(feature = "std")]
use std::vec::Vec;
#[cfg(all(feature = "collections", not(feature = "std")))]
use collections::vec::Vec;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::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 `std` or `collections` feature enabled.
#[cfg(any(feature = "std", feature = "collections"))]
/// Owned variant, only available with the `std` or `alloc` feature enabled.
#[cfg(any(feature = "std", feature = "alloc"))]
Owned(Vec<T>)
}
@ -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 = "std", feature = "collections"))]
#[cfg(any(feature = "std", feature = "alloc"))]
&ManagedSlice::Owned(ref x) => write!(f, "Owned({:?})", x)
}
@ -67,11 +67,11 @@ macro_rules! from_unboxed_slice {
)
}
#[cfg(any(feature = "std", all(feature = "alloc", feature = "collections")))]
#[cfg(any(feature = "std", feature = "alloc"))]
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 = "std", feature = "collections"))]
#[cfg(any(feature = "std", feature = "alloc"))]
impl<T: 'static> From<Vec<T>> for ManagedSlice<'static, T> {
fn from(value: Vec<T>) -> 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 = "std", feature = "collections"))]
#[cfg(any(feature = "std", feature = "alloc"))]
&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 = "std", feature = "collections"))]
#[cfg(any(feature = "std", feature = "alloc"))]
&mut ManagedSlice::Owned(ref mut value) => value
}
}