| 1 | #[doc (hidden)] |
| 2 | #[macro_export ] |
| 3 | macro_rules! __for_range{ |
| 4 | ( $var:ident in $range:expr => $($for_body:tt)* )=>({ |
| 5 | let $crate::pmr::Range{start: mut $var, end} = $range; |
| 6 | while $var < end { |
| 7 | {$($for_body)*} |
| 8 | $var+=1; |
| 9 | } |
| 10 | }) |
| 11 | } |
| 12 | |
| 13 | #[allow (unused_macros)] |
| 14 | macro_rules! identity { |
| 15 | ($($tt:tt)*) => { $($tt)* }; |
| 16 | } |
| 17 | |
| 18 | #[cfg (not(feature = "rust_1_83" ))] |
| 19 | #[doc (hidden)] |
| 20 | #[macro_export ] |
| 21 | macro_rules! __str_const { |
| 22 | ($e:expr) => { |
| 23 | $crate::pmr::__AssertStr { x: $e }.x |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | #[cfg (feature = "rust_1_83" )] |
| 28 | #[doc (hidden)] |
| 29 | #[macro_export ] |
| 30 | macro_rules! __str_const { |
| 31 | ($e:expr) => { |
| 32 | const { $crate::pmr::__AssertStr { x: $e }.x } |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | #[cfg (not(feature = "rust_1_83" ))] |
| 37 | #[doc (hidden)] |
| 38 | #[macro_export ] |
| 39 | macro_rules! __const { |
| 40 | ($ty:ty => $e:expr) => { |
| 41 | $crate::pmr::__AssertType::<$ty> { x: $e }.x |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | #[cfg (feature = "rust_1_83" )] |
| 46 | #[doc (hidden)] |
| 47 | #[macro_export ] |
| 48 | macro_rules! __const { |
| 49 | ($ty:ty => $e:expr) => { |
| 50 | const { $crate::pmr::__AssertType::<$ty> { x: $e }.x } |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | #[doc (hidden)] |
| 55 | #[macro_export ] |
| 56 | macro_rules! iter_copy_slice{ |
| 57 | ( $var:ident in $array:expr => $($for_body:tt)* )=>({ |
| 58 | let mut array: &[_] = &$array; |
| 59 | while let [$var, ref rem @ ..] = *array { |
| 60 | {$($for_body)*} |
| 61 | array = rem; |
| 62 | } |
| 63 | }) |
| 64 | } |
| 65 | |
| 66 | #[doc (hidden)] |
| 67 | #[macro_export ] |
| 68 | macro_rules! __write_pvariant { |
| 69 | (char, $parg:expr, $elem:ident => $out:ident) => {{ |
| 70 | let encoded = $elem.encoded(); |
| 71 | let len = $elem.len(); |
| 72 | |
| 73 | let mut start = 0; |
| 74 | while start < len { |
| 75 | $out.array[$out.len] = encoded[start]; |
| 76 | $out.len += 1; |
| 77 | start += 1; |
| 78 | } |
| 79 | }}; |
| 80 | (int, $parg:expr, $elem:ident => $out:ident) => {{ |
| 81 | let wrapper = $crate::pmr::PWrapper($elem); |
| 82 | |
| 83 | let debug_display; |
| 84 | let bin; |
| 85 | let hex; |
| 86 | |
| 87 | let sa: &$crate::pmr::StartAndArray<[_]> = match $parg.fmt { |
| 88 | $crate::pmr::Formatting::Display => { |
| 89 | debug_display = wrapper.to_start_array_display(); |
| 90 | &debug_display |
| 91 | } |
| 92 | $crate::pmr::Formatting::Debug => match $parg.fmt_flags.num_fmt() { |
| 93 | $crate::pmr::NumberFormatting::Decimal => { |
| 94 | debug_display = wrapper.to_start_array_debug(); |
| 95 | &debug_display |
| 96 | } |
| 97 | $crate::pmr::NumberFormatting::Binary => { |
| 98 | bin = wrapper.to_start_array_binary($parg.fmt_flags); |
| 99 | &bin |
| 100 | } |
| 101 | $crate::pmr::NumberFormatting::Hexadecimal => { |
| 102 | hex = wrapper.to_start_array_hexadecimal($parg.fmt_flags); |
| 103 | &hex |
| 104 | } |
| 105 | }, |
| 106 | }; |
| 107 | |
| 108 | let mut start = sa.start; |
| 109 | while start < sa.array.len() { |
| 110 | $out.array[$out.len] = sa.array[start]; |
| 111 | $out.len += 1; |
| 112 | start += 1; |
| 113 | } |
| 114 | }}; |
| 115 | (str, $parg:expr, $elem:ident => $out:ident) => {{ |
| 116 | let str = $elem.as_bytes(); |
| 117 | let is_display = $parg.fmt.is_display(); |
| 118 | let mut i = 0; |
| 119 | if is_display { |
| 120 | while i < str.len() { |
| 121 | $out.array[$out.len] = str[i]; |
| 122 | $out.len += 1; |
| 123 | i += 1; |
| 124 | } |
| 125 | } else { |
| 126 | $out.array[$out.len] = b'"' ; |
| 127 | $out.len += 1; |
| 128 | while i < str.len() { |
| 129 | use $crate::pmr::{hex_as_ascii, ForEscaping, FOR_ESCAPING}; |
| 130 | |
| 131 | let c = str[i]; |
| 132 | let mut written_c = c; |
| 133 | if c < 128 { |
| 134 | let shifted = 1 << c; |
| 135 | |
| 136 | if (FOR_ESCAPING.is_escaped & shifted) != 0 { |
| 137 | $out.array[$out.len] = b' \\' ; |
| 138 | $out.len += 1; |
| 139 | if (FOR_ESCAPING.is_backslash_escaped & shifted) == 0 { |
| 140 | $out.array[$out.len] = b'x' ; |
| 141 | $out.array[$out.len + 1] = |
| 142 | hex_as_ascii(c >> 4, $crate::pmr::HexFormatting::Upper); |
| 143 | $out.len += 2; |
| 144 | written_c = hex_as_ascii(c & 0b1111, $crate::pmr::HexFormatting::Upper); |
| 145 | } else { |
| 146 | written_c = ForEscaping::get_backslash_escape(c); |
| 147 | }; |
| 148 | } |
| 149 | } |
| 150 | $out.array[$out.len] = written_c; |
| 151 | $out.len += 1; |
| 152 | i += 1; |
| 153 | } |
| 154 | $out.array[$out.len] = b'"' ; |
| 155 | $out.len += 1; |
| 156 | } |
| 157 | }}; |
| 158 | } |
| 159 | |