mirror of
https://github.com/openharmony/third_party_rust_tinyvec.git
synced 2026-07-19 22:33:42 -04:00
Make macros work without any other imports
This commit is contained in:
+3
-3
@@ -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<A: Array> ArrayVec<A> {
|
||||
}
|
||||
|
||||
/// Clone each element of the slice into this `ArrayVec`.
|
||||
///
|
||||
///
|
||||
/// ## Panics
|
||||
/// * If the `ArrayVec` would overflow, this will panic.
|
||||
#[inline]
|
||||
|
||||
+2
-1
@@ -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::*;
|
||||
|
||||
+4
-4
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user