Add feature "std" to arrayvec: Allow opting out of libstd
This commit is contained in:
@@ -19,6 +19,7 @@ branches:
|
|||||||
script:
|
script:
|
||||||
- |
|
- |
|
||||||
([ ! -z "$NODROP_FEATURES" ] || cargo build --verbose --features "$FEATURES") &&
|
([ ! -z "$NODROP_FEATURES" ] || cargo build --verbose --features "$FEATURES") &&
|
||||||
|
([ "$NODEFAULT" != 1 ] || cargo build --verbose --no-default-features) &&
|
||||||
([ ! -z "$NODROP_FEATURES" ] || cargo test --verbose --features "$FEATURES") &&
|
([ ! -z "$NODROP_FEATURES" ] || cargo test --verbose --features "$FEATURES") &&
|
||||||
([ ! -z "$NODROP_FEATURES" ] || cargo test --release --verbose --features "$FEATURES") &&
|
([ ! -z "$NODROP_FEATURES" ] || cargo test --release --verbose --features "$FEATURES") &&
|
||||||
([ ! -z "$NODROP_FEATURES" ] || cargo bench --verbose --features "$FEATURES" -- --test) &&
|
([ ! -z "$NODROP_FEATURES" ] || cargo bench --verbose --features "$FEATURES" -- --test) &&
|
||||||
|
|||||||
+9
-3
@@ -8,11 +8,17 @@ description = "A vector with a fixed capacity, it can be stored on the stack too
|
|||||||
documentation = "http://bluss.github.io/arrayvec"
|
documentation = "http://bluss.github.io/arrayvec"
|
||||||
repository = "https://github.com/bluss/arrayvec"
|
repository = "https://github.com/bluss/arrayvec"
|
||||||
|
|
||||||
keywords = ["stack", "vector", "array", "string", "data-structure"]
|
keywords = ["stack", "vector", "array", "data-structure", "no_std"]
|
||||||
|
|
||||||
[dependencies.odds]
|
[dependencies.odds]
|
||||||
version = "0.2"
|
version = "0.2.12"
|
||||||
|
default-features = false
|
||||||
|
|
||||||
[dependencies.nodrop]
|
[dependencies.nodrop]
|
||||||
version = "0.1.4"
|
version = "0.1.6"
|
||||||
path = "nodrop"
|
path = "nodrop"
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["std"]
|
||||||
|
std = ["odds/std", "nodrop/std"]
|
||||||
|
|||||||
+4
-4
@@ -2,6 +2,7 @@ use std::borrow::Borrow;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::ptr;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
@@ -116,14 +117,13 @@ impl<A: Array<Item=u8>> ArrayString<A> {
|
|||||||
/// assert_eq!(overflow2.unwrap_err().element(), "ef");
|
/// assert_eq!(overflow2.unwrap_err().element(), "ef");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn push_str<'a>(&mut self, s: &'a str) -> Result<(), CapacityError<&'a str>> {
|
pub fn push_str<'a>(&mut self, s: &'a str) -> Result<(), CapacityError<&'a str>> {
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
if s.len() > self.capacity() - self.len() {
|
if s.len() > self.capacity() - self.len() {
|
||||||
return Err(CapacityError::new(s));
|
return Err(CapacityError::new(s));
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
let sl = slice::from_raw_parts_mut(self.xs.as_mut_ptr(), A::capacity());
|
let dst = self.xs.as_mut_ptr().offset(self.len() as isize);
|
||||||
(&mut sl[self.len()..]).write(s.as_bytes()).unwrap();
|
let src = s.as_ptr();
|
||||||
|
ptr::copy_nonoverlapping(src, dst, s.len());
|
||||||
let newl = self.len() + s.len();
|
let newl = self.len() + s.len();
|
||||||
self.set_len(newl);
|
self.set_len(newl);
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-5
@@ -1,8 +1,20 @@
|
|||||||
|
//! **arrayvec** provides the types `ArrayVec` and `ArrayString`:
|
||||||
|
//! array-backed vector and string types, which store their contents inline.
|
||||||
|
//!
|
||||||
|
//! The **arrayvec** crate has the following cargo feature flags:
|
||||||
|
//!
|
||||||
|
//! - `std`
|
||||||
|
//! - Optional, enabled by default
|
||||||
|
//! - Requires Rust 1.6 *to disable*
|
||||||
|
//! - Use libstd
|
||||||
|
#![cfg_attr(not(feature="std"), no_std)]
|
||||||
extern crate odds;
|
extern crate odds;
|
||||||
extern crate nodrop;
|
extern crate nodrop;
|
||||||
|
|
||||||
|
#[cfg(not(feature="std"))]
|
||||||
|
extern crate core as std;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::io;
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
@@ -12,15 +24,20 @@ use std::ops::{
|
|||||||
};
|
};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
use nodrop::NoDrop;
|
|
||||||
|
|
||||||
// extra traits
|
// extra traits
|
||||||
use std::any::Any;
|
|
||||||
use std::borrow::{Borrow, BorrowMut};
|
use std::borrow::{Borrow, BorrowMut};
|
||||||
use std::error::Error;
|
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
#[cfg(feature="std")]
|
||||||
|
use std::io;
|
||||||
|
#[cfg(feature="std")]
|
||||||
|
use std::error::Error;
|
||||||
|
#[cfg(feature="std")]
|
||||||
|
use std::any::Any; // core but unused
|
||||||
|
|
||||||
|
use nodrop::NoDrop;
|
||||||
|
|
||||||
mod array;
|
mod array;
|
||||||
mod array_string;
|
mod array_string;
|
||||||
|
|
||||||
@@ -686,7 +703,10 @@ impl<A: Array> Ord for ArrayVec<A> where A::Item: Ord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature="std")]
|
||||||
/// `Write` appends written data to the end of the vector.
|
/// `Write` appends written data to the end of the vector.
|
||||||
|
///
|
||||||
|
/// Requires `features="std"`.
|
||||||
impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
|
impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
|
||||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -729,12 +749,16 @@ impl<T> CapacityError<T> {
|
|||||||
|
|
||||||
const CAPERROR: &'static str = "insufficient capacity";
|
const CAPERROR: &'static str = "insufficient capacity";
|
||||||
|
|
||||||
|
#[cfg(feature="std")]
|
||||||
|
/// Requires `features="std"`.
|
||||||
impl<T: Any> Error for CapacityError<T> {
|
impl<T: Any> Error for CapacityError<T> {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
CAPERROR
|
CAPERROR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature="std")]
|
||||||
|
/// Requires `features="std"`.
|
||||||
impl<T> fmt::Display for CapacityError<T> {
|
impl<T> fmt::Display for CapacityError<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", CAPERROR)
|
write!(f, "{}", CAPERROR)
|
||||||
|
|||||||
Reference in New Issue
Block a user