1use crate::Vectorable;
2use alloc::string::String;
3use alloc::vec::Vec;
4
5#[doc(hidden)]
6#[macro_export]
7#[allow(unused_macros)]
8macro_rules! impl_vec {
9 ($from: ty, $to: ty, $transform: expr) => {
10 impl Vectorable<$to> for $from {
11 #[inline]
12 fn into(&self) -> Vec<$to> {
13 $transform(self)
14 }
15 }
16 };
17}
18
19#[doc(hidden)]
20#[macro_export]
21#[allow(unused_macros)]
22macro_rules! impl_vec_k {
23 ($from: ty, $transform: expr) => {
24 impl<K> Vectorable<K> for $from
25 where
26 K: Copy + PartialEq + PartialOrd,
27 {
28 #[inline]
29 fn into(&self) -> Vec<K> {
30 $transform(self)
31 }
32 }
33 };
34}
35
36impl_vec!(&'static str, u8, |x: &'static str| x.as_bytes().to_owned());
37impl_vec!(String, u8, |x: &String| x.as_bytes().to_owned());
38
39impl_vec!(&'static str, u32, |x: &'static str| x
40 .chars()
41 .map(|x| x as u32)
42 .collect());
43impl_vec!(String, u32, |x: &String| x
44 .chars()
45 .map(|x| x as u32)
46 .collect());
47
48impl_vec!(&'static str, char, |x: &'static str| x.chars().collect());
49impl_vec!(String, char, |x: &String| x.chars().collect());
50
51impl_vec_k!(Vec<K>, |x: &Vec<K>| x.to_owned());
52impl_vec_k!(&[K], |x: &[K]| x.to_owned());