1 | pub struct StrRepeatArgs { |
2 | pub str: &'static str, |
3 | pub str_len: usize, |
4 | pub out_len: usize, |
5 | pub overflowed_len: Option<usize>, |
6 | pub repeat: usize, |
7 | } |
8 | |
9 | #[allow (non_snake_case)] |
10 | pub const fn StrRepeatArgs(str: &'static str, repeat: usize) -> StrRepeatArgs { |
11 | let str_len: usize = str.len(); |
12 | let (mul: usize, overflowed: bool) = str_len.overflowing_mul(repeat); |
13 | |
14 | let (out_len: usize, overflowed_len: Option, repeat: usize) = if overflowed { |
15 | (str_len, Some(mul), 1) |
16 | } else { |
17 | (mul, None, repeat) |
18 | }; |
19 | |
20 | StrRepeatArgs { |
21 | str, |
22 | str_len, |
23 | out_len, |
24 | overflowed_len, |
25 | repeat, |
26 | } |
27 | } |
28 | |
29 | impl StrRepeatArgs { |
30 | pub const fn assert_valid(&self) { |
31 | if let Some(overflowed_len: usize) = self.overflowed_len { |
32 | [/* the returned string is too large */][overflowed_len] |
33 | } |
34 | } |
35 | } |
36 | |