azure_core/request_options/
max_item_count.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::headers::{self, Header};

/// The max number of items in the collection
#[derive(Debug, Clone, Copy)]
pub struct MaxItemCount(i32);

impl MaxItemCount {
    /// Create a new `MaxItemCount`
    pub fn new(count: i32) -> Self {
        Self(count)
    }
}

impl Header for MaxItemCount {
    fn name(&self) -> headers::HeaderName {
        headers::MAX_ITEM_COUNT
    }

    fn value(&self) -> headers::HeaderValue {
        let count = if self.0 <= 0 { -1 } else { self.0 };
        format!("{count}").into()
    }
}

impl From<i32> for MaxItemCount {
    fn from(count: i32) -> Self {
        Self::new(count)
    }
}

impl Default for MaxItemCount {
    fn default() -> Self {
        MaxItemCount::new(-1)
    }
}