rocket_multipart_form_data/
repetition.rs1#[derive(Debug, Clone, Copy)]
2pub(crate) enum RepetitionCounter {
3 Fixed(u32),
4 Infinite,
5}
6
7impl RepetitionCounter {
8 #[inline]
9 pub fn decrease_check_is_over(&mut self) -> bool {
10 match self {
11 RepetitionCounter::Fixed(n) => {
12 debug_assert!(*n > 0);
13
14 *n -= 1;
15 *n == 0
16 },
17 RepetitionCounter::Infinite => false,
18 }
19 }
20}
21
22impl Default for RepetitionCounter {
23 #[inline]
24 fn default() -> Self {
25 RepetitionCounter::Fixed(1)
26 }
27}
28
29#[derive(Debug, Clone, Copy)]
30pub struct Repetition {
32 counter: RepetitionCounter,
33}
34
35impl Repetition {
36 #[inline]
37 #[must_use]
38 pub const fn new() -> Repetition {
40 Repetition {
41 counter: RepetitionCounter::Fixed(1)
42 }
43 }
44
45 #[inline]
46 #[must_use]
47 pub const fn fixed(count: u32) -> Repetition {
51 Repetition {
52 counter: RepetitionCounter::Fixed(if count == 0 { 1 } else { count })
53 }
54 }
55
56 #[inline]
57 #[must_use]
58 pub const fn infinite() -> Repetition {
62 Repetition {
63 counter: RepetitionCounter::Infinite
64 }
65 }
66
67 #[inline]
68 pub(crate) fn decrease_check_is_over(&mut self) -> bool {
69 self.counter.decrease_check_is_over()
70 }
71}
72
73impl Default for Repetition {
74 #[inline]
75 fn default() -> Self {
77 Repetition::new()
78 }
79}