Skip to content

Commit 9534a6b

Browse files
committed
Modifies lib.rs and Cargo.toml
lib.rs: Alloc feature Cargo.toml: New features and 2018 edition
1 parent 830d32b commit 9534a6b

File tree

2 files changed

+50
-55
lines changed

2 files changed

+50
-55
lines changed

Cargo.toml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
[package]
2-
name = "smallvec"
3-
version = "0.6.10"
42
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
5-
license = "MIT/Apache-2.0"
6-
repository = "https://github.com/servo/rust-smallvec"
7-
description = "'Small vector' optimization: store up to a small number of items on the stack"
8-
keywords = ["small", "vec", "vector", "stack", "no_std"]
93
categories = ["data-structures"]
10-
readme = "README.md"
4+
description = "'Small vector' optimization: store up to a small number of items on the stack"
115
documentation = "https://doc.servo.org/smallvec/"
12-
13-
[features]
14-
std = []
15-
union = []
16-
default = ["std"]
17-
specialization = []
18-
may_dangle = []
19-
20-
[lib]
6+
edition = "2018"
7+
keywords = ["small", "vec", "vector", "stack", "no_std"]
8+
license = "MIT/Apache-2.0"
219
name = "smallvec"
22-
path = "lib.rs"
10+
readme = "README.md"
11+
repository = "https://github.com/servo/rust-smallvec"
12+
version = "0.6.10"
2313

2414
[dependencies]
2515
serde = { version = "1", optional = true }
2616

2717
[dev_dependencies]
2818
bincode = "1.0.1"
19+
20+
[features]
21+
alloc = []
22+
const_generics = []
23+
default = ["alloc"]
24+
may_dangle = []
25+
specialization = []
26+
std = ["alloc"]
27+
union = []
28+
29+
[lib]
30+
name = "smallvec"
31+
path = "lib.rs"

lib.rs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,39 @@
2828
//! To use this feature add `features = ["union"]` in the `smallvec` section of Cargo.toml.
2929
//! Note that this feature requires a nightly compiler (for now).
3030
31-
#![cfg_attr(not(feature = "std"), no_std)]
32-
#![cfg_attr(not(feature = "std"), feature(alloc))]
33-
#![cfg_attr(feature = "union", feature(untagged_unions))]
34-
#![cfg_attr(feature = "specialization", feature(specialization))]
3531
#![cfg_attr(feature = "may_dangle", feature(dropck_eyepatch))]
32+
#![cfg_attr(feature = "specialization", feature(specialization))]
33+
#![cfg_attr(feature = "union", feature(untagged_unions))]
34+
#![cfg_attr(not(feature = "alloc"), no_std)]
3635
#![deny(missing_docs)]
3736

38-
39-
#[cfg(not(feature = "std"))]
40-
#[macro_use]
37+
#[cfg(feature = "alloc")]
4138
extern crate alloc;
4239

43-
#[cfg(not(feature = "std"))]
44-
use alloc::vec::Vec;
45-
4640
#[cfg(feature = "serde")]
4741
extern crate serde;
4842

49-
#[cfg(not(feature = "std"))]
50-
mod std {
51-
pub use core::*;
52-
}
53-
54-
use std::borrow::{Borrow, BorrowMut};
55-
use std::cmp;
56-
use std::fmt;
57-
use std::hash::{Hash, Hasher};
58-
use std::iter::{IntoIterator, FromIterator, repeat};
59-
use std::mem;
60-
use std::mem::ManuallyDrop;
61-
use std::ops;
62-
use std::ptr;
63-
use std::slice;
43+
use core::{
44+
borrow::{Borrow, BorrowMut},
45+
cmp,
46+
fmt,
47+
hash::{Hash, Hasher},
48+
iter::{IntoIterator, FromIterator, repeat},
49+
mem::{ManuallyDrop, self},
50+
ops,
51+
ptr,
52+
slice,
53+
};
6454
#[cfg(feature = "std")]
6555
use std::io;
6656
#[cfg(feature = "serde")]
67-
use serde::ser::{Serialize, Serializer, SerializeSeq};
68-
#[cfg(feature = "serde")]
69-
use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor};
70-
#[cfg(feature = "serde")]
71-
use std::marker::PhantomData;
57+
use {
58+
serde::{
59+
ser::{Serialize, Serializer, SerializeSeq},
60+
de::{Deserialize, Deserializer, SeqAccess, Visitor},
61+
},
62+
core::marker::PhantomData
63+
};
7264

7365
/// Creates a [`SmallVec`] containing the arguments.
7466
///
@@ -821,7 +813,7 @@ impl<A: Array> SmallVec<A> {
821813
}
822814

823815
let (lower_size_bound, _) = iter.size_hint();
824-
assert!(lower_size_bound <= std::isize::MAX as usize); // Ensure offset is indexable
816+
assert!(lower_size_bound <= core::isize::MAX as usize); // Ensure offset is indexable
825817
assert!(index + lower_size_bound >= index); // Protect against overflow
826818
self.reserve(lower_size_bound);
827819

@@ -1121,7 +1113,7 @@ impl<A: Array> SmallVec<A> where A::Item: Clone {
11211113
let mut local_len = SetLenOnDrop::new(len_ptr);
11221114

11231115
for i in 0..n as isize {
1124-
::std::ptr::write(ptr.offset(i), elem.clone());
1116+
core::ptr::write(ptr.offset(i), elem.clone());
11251117
local_len.increment_len(1);
11261118
}
11271119
}
@@ -1606,9 +1598,9 @@ impl_array!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32
16061598

16071599
#[cfg(test)]
16081600
mod tests {
1609-
use SmallVec;
1601+
use crate::SmallVec;
16101602

1611-
use std::iter::FromIterator;
1603+
use core::iter::FromIterator;
16121604

16131605
#[cfg(feature = "std")]
16141606
use std::borrow::ToOwned;
@@ -1766,7 +1758,7 @@ mod tests {
17661758

17671759
#[test]
17681760
fn into_iter_drop() {
1769-
use std::cell::Cell;
1761+
use core::cell::Cell;
17701762

17711763
struct DropCounter<'a>(&'a Cell<i32>);
17721764

@@ -2061,7 +2053,7 @@ mod tests {
20612053

20622054
#[test]
20632055
fn test_borrow() {
2064-
use std::borrow::Borrow;
2056+
use core::borrow::Borrow;
20652057

20662058
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
20672059
a.push(1);
@@ -2074,7 +2066,7 @@ mod tests {
20742066

20752067
#[test]
20762068
fn test_borrow_mut() {
2077-
use std::borrow::BorrowMut;
2069+
use core::borrow::BorrowMut;
20782070

20792071
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
20802072
a.push(1);
@@ -2279,7 +2271,7 @@ mod tests {
22792271
#[cfg(feature = "std")]
22802272
#[test]
22812273
fn test_write() {
2282-
use io::Write;
2274+
use std::io::Write;
22832275

22842276
let data = [1, 2, 3, 4, 5];
22852277

0 commit comments

Comments
 (0)