azure_core/request_options/
max_results.rsuse crate::{AppendToUrlQuery, Url};
use std::num::NonZeroU32;
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
pub struct MaxResults(NonZeroU32);
impl MaxResults {
pub fn new(max_results: NonZeroU32) -> Self {
Self(max_results)
}
}
impl AppendToUrlQuery for MaxResults {
fn append_to_url_query(&self, url: &mut Url) {
url.query_pairs_mut()
.append_pair("maxresults", &format!("{}", self.0));
}
}
impl From<NonZeroU32> for MaxResults {
fn from(max_results: NonZeroU32) -> Self {
Self::new(max_results)
}
}
impl TryFrom<u32> for MaxResults {
type Error = String;
fn try_from(max_results: u32) -> Result<Self, Self::Error> {
match NonZeroU32::new(max_results) {
Some(max_results) => Ok(max_results.into()),
None => Err(format!(
"number {max_results} is not a valid NonZeroU32 value"
)),
}
}
}