konst/macros/
bytes_fn_macros.rs1macro_rules! impl_bytes_function {
2 (
3 strip_prefix;
4 left = $left:expr;
5 right = $right:expr;
6 on_error = $on_error:expr,
7 ) => {
8 if $left.len() < $right.len() {
9 $on_error
10 }
11
12 loop {
13 match ($left, $right) {
14 ([lb, rem_slice @ ..], [rb, rem_matched @ ..]) => {
15 $left = rem_slice;
16 $right = rem_matched;
17
18 if *lb != *rb {
19 $on_error
20 }
21 }
22 (rem, _) => {
23 $left = rem;
24 break;
25 }
26 }
27 }
28 };
29 (
30 strip_suffix;
31 left = $left:expr;
32 right = $right:expr;
33 on_error = $on_error:expr,
34 ) => {
35 if $left.len() < $right.len() {
36 $on_error
37 }
38
39 loop {
40 match ($left, $right) {
41 ([rem_slice @ .., lb], [rem_matched @ .., rb]) => {
42 $left = rem_slice;
43 $right = rem_matched;
44
45 if *lb != *rb {
46 $on_error
47 }
48 }
49 (rem, _) => {
50 $left = rem;
51 break;
52 }
53 }
54 }
55 };
56}