const_str/__ctfe/
to_byte_array.rs1pub struct ToByteArray<T>(pub T);
2
3impl ToByteArray<&str> {
4 pub const fn const_eval<const N: usize>(&self) -> [u8; N] {
5 crate::bytes::clone(self.0.as_bytes())
6 }
7}
8
9impl<const L: usize> ToByteArray<&[u8; L]> {
10 pub const fn const_eval<const N: usize>(&self) -> [u8; N] {
11 crate::bytes::clone(self.0)
12 }
13}
14
15#[macro_export]
28macro_rules! to_byte_array {
29 ($s: expr) => {{
30 const OUTPUT_LEN: usize = $s.len();
31 $crate::__ctfe::ToByteArray($s).const_eval::<OUTPUT_LEN>()
32 }};
33}