From 45275fbbc265b767e33e9b62ead7e873b464bc3b Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Tue, 28 Jan 2020 12:46:39 +0100 Subject: [PATCH] Make macros work without any other imports --- src/arrayvec.rs | 6 +++--- src/lib.rs | 3 ++- src/tinyvec.rs | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/arrayvec.rs b/src/arrayvec.rs index bcf8be9..5ccd5a9 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -19,13 +19,13 @@ use super::*; macro_rules! array_vec { ($array_type:ty) => { { - let av: ArrayVec<$array_type> = Default::default(); + let av: $crate::ArrayVec<$array_type> = Default::default(); av } }; ($array_type:ty, $($elem:expr),*) => { { - let mut av: ArrayVec<$array_type> = Default::default(); + let mut av: $crate::ArrayVec<$array_type> = Default::default(); $( av.push($elem); )* av } @@ -251,7 +251,7 @@ impl ArrayVec { } /// Clone each element of the slice into this `ArrayVec`. - /// + /// /// ## Panics /// * If the `ArrayVec` would overflow, this will panic. #[inline] diff --git a/src/lib.rs b/src/lib.rs index bd22858..238779c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,8 @@ use core::{ }; #[cfg(feature = "alloc")] -extern crate alloc; +#[doc(hidden)] // re-export for macros +pub extern crate alloc; mod array; pub use array::*; diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 0eb686e..c6b2e39 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -25,7 +25,7 @@ use alloc::vec::Vec; macro_rules! tiny_vec { ($array_type:ty) => { { - let mut tv: TinyVec<$array_type> = Default::default(); + let mut tv: $crate::TinyVec<$array_type> = Default::default(); tv } }; @@ -42,10 +42,10 @@ macro_rules! tiny_vec { const INVOKED_ELEM_COUNT: usize = 0 $( + { let _ = stringify!($elem); 1 })*; // If we have more `$elem` than the `CAPACITY` we will simply go directly // to constructing on the heap. - let av: TinyVec<$array_type> = if INVOKED_ELEM_COUNT <= <$array_type as Array>::CAPACITY { - TinyVec::<$array_type>::Inline(array_vec!($array_type, $($elem),*)) + let av: $crate::TinyVec<$array_type> = if INVOKED_ELEM_COUNT <= <$array_type as $crate::Array>::CAPACITY { + $crate::TinyVec::<$array_type>::Inline($crate::array_vec!($array_type, $($elem),*)) } else { - TinyVec::<$array_type>::Heap(vec!($($elem),*)) + $crate::TinyVec::<$array_type>::Heap($crate::alloc::vec!($($elem),*)) }; av }