diff --git a/Cargo.toml b/Cargo.toml index 256bff8..7163251 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ harness = false [features] default = ["std"] std = [] +nightly = [] [profile.bench] debug = true diff --git a/src/len_type.rs b/src/len_type.rs index f9dfe8c..d241395 100644 --- a/src/len_type.rs +++ b/src/len_type.rs @@ -6,8 +6,12 @@ macro_rules! impl_lenuint { impl $LenUint for $ty { const MAX: usize = <$ty>::MAX as usize; const ZERO: Self = 0; - fn from_usize(n: usize) -> Self { n as $ty } - fn to_usize(self) -> usize { self as usize } + fn from_usize(n: usize) -> Self { + n as $ty + } + fn to_usize(self) -> usize { + self as usize + } } }; } @@ -15,6 +19,7 @@ macro_rules! impl_lenuint { macro_rules! impl_default_lentype_from_cap { ($LenT:ty => $($CAP:literal),*) => { $( + #[cfg(feature = "nightly")] impl CapToDefaultLenType for ConstGenericSmuggler<$CAP> { type T = $LenT; } @@ -22,7 +27,7 @@ macro_rules! impl_default_lentype_from_cap { }; } -pub trait LenUint: Add + Sub + Copy + PartialOrd + PartialEq + private::Sealed { +pub trait LenUint: Add + Sub + Copy + PartialOrd + PartialEq + private::Sealed { const MAX: usize; const ZERO: Self; fn from_usize(n: usize) -> Self; @@ -46,9 +51,16 @@ pub trait CapToDefaultLenType { type T: LenUint; } +impl CapToDefaultLenType for ConstGenericSmuggler { + #[cfg(not(feature = "nightly"))] + type T = u32; + #[cfg(feature = "nightly")] + default type T = u32; +} + impl_default_lentype_from_cap!(u8 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64, 100, 128, 200, 255); impl_default_lentype_from_cap!(u16 => 256, 500, 512, 1000, 1024, 2048, 4096, 8192, 16384, 32768, 65535); -impl_default_lentype_from_cap!(u32 => 65536, 1000000, 4294967295); +// impl_default_lentype_from_cap!(u32 => 65536, 1000000, 4294967295); impl_default_lentype_from_cap!(u64 => 18446744073709551615); pub trait CapFitsInLenType { diff --git a/src/lib.rs b/src/lib.rs index 9b6cbda..71140e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! **arrayvec** provides the types [`ArrayVec`] and [`ArrayString`]: +//! **arrayvec** provides the types [`ArrayVec`] and [`ArrayString`]: //! array-backed vector and string types, which store their contents inline. //! //! The arrayvec package has the following cargo features: @@ -19,25 +19,26 @@ //! //! This version of arrayvec requires Rust 1.51 or later. //! -#![doc(html_root_url="https://docs.rs/arrayvec/0.7/")] -#![cfg_attr(not(feature="std"), no_std)] +#![doc(html_root_url = "https://docs.rs/arrayvec/0.7/")] +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(feature = "nightly", feature(specialization))] -#[cfg(feature="serde")] +#[cfg(feature = "serde")] extern crate serde; -#[cfg(not(feature="std"))] +#[cfg(not(feature = "std"))] extern crate core as std; -mod len_type; -mod arrayvec_impl; -mod arrayvec; mod array_string; +mod arrayvec; +mod arrayvec_impl; mod char; mod errors; +mod len_type; mod utils; pub use crate::array_string::ArrayString; pub use crate::errors::CapacityError; pub use len_type::LenUint; -pub use crate::arrayvec::{ArrayVec, IntoIter, Drain}; +pub use crate::arrayvec::{ArrayVec, Drain, IntoIter};