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 pub fn new() -> Repetition {
39 Repetition {
40 counter: RepetitionCounter::Fixed(1)
41 }
42 }
43
44 #[inline]
45 pub fn fixed(count: u32) -> Repetition {
47 if count == 0 {
48 eprintln!(
49 "The count of fixed repetition for a `MultipartFormDataField` instance should be \
50 bigger than 0. Use 1 instead."
51 );
52
53 Repetition::new()
54 } else {
55 Repetition {
56 counter: RepetitionCounter::Fixed(count)
57 }
58 }
59 }
60
61 #[inline]
62 pub fn infinite() -> Repetition {
64 Repetition {
65 counter: RepetitionCounter::Infinite
66 }
67 }
68
69 #[inline]
70 pub(crate) fn decrease_check_is_over(&mut self) -> bool {
71 self.counter.decrease_check_is_over()
72 }
73}
74
75impl Default for Repetition {
76 #[inline]
77 fn default() -> Self {
79 Repetition::new()
80 }
81}