From c8bd5cc2b2cd3ca4fa7f7daf844dd0821e3d7553 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Mon, 6 Jan 2020 20:28:09 -0700 Subject: [PATCH] Try to adopt 1.24 as the CI version This would allow our crate to be used as a dependency of the `unicode-segmentation` crate. --- .travis.yml | 21 +++++++++++++++++++++ Cargo.toml | 2 +- appveyor.yml | 30 ++++++++++++++++++++++++++++++ src/lib.rs | 45 +++++++++++++++------------------------------ tests/basic.rs | 6 ++++-- 5 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 .travis.yml create mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..44941d0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ + +git: + quiet: true + +language: rust + +cache: + cargo + +rust: + - 1.24.0 + - stable + +matrix: + include: + - os: linux + - os: osx + +script: + - cargo build + - cargo test diff --git a/Cargo.toml b/Cargo.toml index 1708c88..38302f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "tinyvec" description = "Just, really the littlest Vec you could need. So smol." version = "0.0.1-alpha.0" authors = ["Lokathor "] -edition = "2018" +#edition = "2018" # until our min version is allowed to go up, 2015 it is. license = "Zlib" keywords = ["vec", "no_std", "smol"] categories = ["data-structures", "no-std"] diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..6c51465 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,30 @@ + +os: Visual Studio 2015 + +matrix: + fast_finish: true + +environment: + matrix: + - channel: 1.24.0 + target: i686-pc-windows-msvc + - channel: 1.24.0 + target: x86_64-pc-windows-msvc + - channel: 1.24.0 + target: i686-pc-windows-gnu + - channel: 1.24.0 + target: x86_64-pc-windows-gnu + +install: + # Setup Rust + - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe + - rustup-init -y --default-toolchain %channel% --default-host %target% + - set PATH=%PATH%;%USERPROFILE%\.cargo\bin + - rustc -vV + - cargo -vV + +build: false + +test_script: + - cargo build + - cargo test diff --git a/src/lib.rs b/src/lib.rs index 0f07a95..3ca3e0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,9 +3,10 @@ //! Just, really the littlest Vec you could need. So smol. -use core::ops::{Deref, DerefMut}; -use core::mem::replace; -use core::mem::needs_drop; +use core::{ + mem::{needs_drop, replace}, + ops::{Deref, DerefMut}, +}; extern crate alloc; use alloc::vec::Vec; @@ -27,35 +28,27 @@ pub struct TinyVec(Payload); // TODO: impl a better Debug -impl Default for TinyVec { +impl Default for TinyVec { fn default() -> Self { Self::new() } } -impl Deref for TinyVec { +impl Deref for TinyVec { type Target = [T]; fn deref(&self) -> &[T] { match &self.0 { - Payload::Inline { len, data } => { - &data[..*len] - } - Payload::Heap(vec) => { - &vec - } + Payload::Inline { len, data } => &data[..*len], + Payload::Heap(vec) => &vec, } } } -impl DerefMut for TinyVec { +impl DerefMut for TinyVec { fn deref_mut(&mut self) -> &mut [T] { match &mut self.0 { - Payload::Inline { len, data } => { - &mut data[..*len] - } - Payload::Heap(ref mut vec) => { - &mut vec[..] - } + Payload::Inline { len, data } => &mut data[..*len], + Payload::Heap(ref mut vec) => &mut vec[..], } } } @@ -92,26 +85,20 @@ impl TinyVec { data[*len] = val; *len += 1; } - Payload::Heap(ref mut vec) => { - vec.push(val) - } + Payload::Heap(ref mut vec) => vec.push(val), } } pub fn pop(&mut self) -> Option { match &mut self.0 { - Payload::Inline { len: 0, .. } => { - None - } + Payload::Inline { len: 0, .. } => None, Payload::Inline { len, data } => { debug_assert!(*len > 0, "pop: illegal len: {}", len); let out = replace(&mut data[*len - 1], T::default()); *len -= 1; Some(out) } - Payload::Heap(ref mut vec) => { - vec.pop() - } + Payload::Heap(ref mut vec) => vec.pop(), } } @@ -127,9 +114,7 @@ impl TinyVec { *len = (*len).min(new_len); } } - Payload::Heap(ref mut vec) => { - vec.truncate(new_len) - } + Payload::Heap(ref mut vec) => vec.truncate(new_len), } } } diff --git a/tests/basic.rs b/tests/basic.rs index 4818699..b7ec62e 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,7 +1,9 @@ #![allow(bad_style)] +extern crate tinyvec; use tinyvec::*; +extern crate core; use core::ops::Deref; #[test] @@ -9,12 +11,12 @@ fn TinyVec_push_pop() { let mut tv = TinyVec::new(); assert_eq!(tv.pop(), None); - + tv.push(5_i32); assert_eq!(tv.pop(), Some(5_i32)); assert_eq!(tv.len(), 0); - for i in 0 .. 10 { + for i in 0..10 { tv.push(i); } assert_eq!(tv.len(), 10);