azure_core/request_options/
max_results.rs1use crate::{AppendToUrlQuery, Url};
2use std::num::NonZeroU32;
3
4#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
10pub struct MaxResults(NonZeroU32);
11
12impl MaxResults {
13 pub fn new(max_results: NonZeroU32) -> Self {
14 Self(max_results)
15 }
16}
17
18impl AppendToUrlQuery for MaxResults {
19 fn append_to_url_query(&self, url: &mut Url) {
20 url.query_pairs_mut()
21 .append_pair("maxresults", &format!("{}", self.0));
22 }
23}
24
25impl From<NonZeroU32> for MaxResults {
26 fn from(max_results: NonZeroU32) -> Self {
27 Self::new(max_results)
28 }
29}
30
31impl TryFrom<u32> for MaxResults {
32 type Error = String;
33
34 fn try_from(max_results: u32) -> Result<Self, Self::Error> {
35 match NonZeroU32::new(max_results) {
36 Some(max_results) => Ok(max_results.into()),
37 None => Err(format!(
38 "number {max_results} is not a valid NonZeroU32 value"
39 )),
40 }
41 }
42}