From 98fdc1890d0d0f1b4d2414775f31a92937260808 Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 1 Jan 2021 22:54:32 +0000 Subject: [PATCH] ext improv --- Cargo.lock | 10 ++++++++++ Cargo.toml | 6 ++++++ src/delta.rs | 2 +- src/ext.rs | 20 +++++++++++++++++++- src/main.rs | 2 ++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d2c3426..3c2b35a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1028,6 +1028,15 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "smallvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0" +dependencies = [ + "serde", +] + [[package]] name = "socket2" version = "0.3.19" @@ -1393,6 +1402,7 @@ dependencies = [ "difference", "futures", "serde", + "smallvec", "tokio", "warp", ] diff --git a/Cargo.toml b/Cargo.toml index 0e36122..e2149e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,9 +5,15 @@ version = "0.1.0" authors = ["Avril "] edition = "2018" +[features] +default = ["nightly"] + +nightly = ["smallvec/const_generics"] + [dependencies] difference = "2.0.0" futures = "0.3.8" serde = {version = "1.0.118", features=["derive"]} +smallvec = {version = "1.6.0", features= ["union", "serde", "write"]} tokio = {version = "0.2", features=["full"] } warp = "0.2.5" diff --git a/src/delta.rs b/src/delta.rs index bcbb83a..6bf6b2f 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -160,7 +160,7 @@ impl Delta }, DeltaKind::Clear => inserter.clear(), DeltaKind::Truncate => inserter.truncate(self.location), - DeltaKind::Shift => ((),inserter.drain(..self.location)).0, + DeltaKind::Shift => drop(inserter.drain(..self.location)), } } } diff --git a/src/ext.rs b/src/ext.rs index 926b936..568e327 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -4,6 +4,7 @@ use std::{ fmt, ops, }; +use smallvec::SmallVec; /// Wrapper to derive debug for types that don't implement it. #[repr(transparent)] @@ -83,6 +84,15 @@ impl BackInserter for Vec } } +impl BackInserter for SmallVec + where T: smallvec::Array +{ + #[inline] fn push_back(&mut self, value: T) + { + self.push(value) + } +} + /// Absracts a closure for `BackInserter`. pub struct BackInsertPass(F, PhantomData) where F: FnMut(T); @@ -140,6 +150,14 @@ where T: BackInserter } } +impl BackInserter for Option +{ + fn push_back(&mut self, value: T) + { + *self = Some(value); + } +} + pub trait VecExt { /// Insert many elements with exact size iterator @@ -290,7 +308,7 @@ mod tests assert_eq!(&vec[..], &vec2[..]); } - #[cfg(nightly)] + #[cfg(feature="nightly")] mod benchmatks { use super::super::*; diff --git a/src/main.rs b/src/main.rs index bf783ae..4d5b736 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ +#![cfg_attr(feature="nightly", feature(test))] #![allow(dead_code)] +#[cfg(all(feature="nightly", test))] extern crate test; #[macro_use] extern crate serde; #[macro_use] mod ext; use ext::*;