1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
pub struct ToByteArray<T>(pub T);
impl ToByteArray<&str> {
pub const fn const_eval<const N: usize>(&self) -> [u8; N] {
crate::bytes::clone(self.0.as_bytes())
}
}
impl<const L: usize> ToByteArray<&[u8; L]> {
pub const fn const_eval<const N: usize>(&self) -> [u8; N] {
crate::bytes::clone(self.0)
}
}
#[macro_export]
macro_rules! to_byte_array {
($s: expr) => {{
const OUTPUT_LEN: usize = $crate::len!($s);
$crate::__ctfe::ToByteArray($s).const_eval::<OUTPUT_LEN>()
}};
}