azure_core/request_options/
next_marker.rs

1use crate::{
2    headers::{self, Headers},
3    AppendToUrlQuery, Url,
4};
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct NextMarker(String);
9
10impl NextMarker {
11    pub fn new(next_marker: String) -> Self {
12        Self(next_marker)
13    }
14
15    pub fn from_possibly_empty_string(next_marker: Option<String>) -> Option<Self> {
16        if let Some("") = next_marker.as_deref() {
17            None
18        } else {
19            next_marker.map(Into::into)
20        }
21    }
22
23    pub fn as_str(&self) -> &str {
24        &self.0
25    }
26
27    pub fn append_to_url_query_as_continuation(&self, url: &mut Url) {
28        url.query_pairs_mut().append_pair("continuation", &self.0);
29    }
30
31    pub fn from_header_optional(headers: &Headers) -> crate::Result<Option<Self>> {
32        let header_as_str = headers.get_optional_str(&headers::CONTINUATION);
33
34        Ok(header_as_str
35            .filter(|h| !h.is_empty())
36            .map(|h| NextMarker::new(h.to_owned())))
37    }
38}
39
40impl AppendToUrlQuery for NextMarker {
41    fn append_to_url_query(&self, url: &mut Url) {
42        url.query_pairs_mut().append_pair("marker", &self.0);
43    }
44}
45
46impl From<String> for NextMarker {
47    fn from(next_marker: String) -> Self {
48        Self::new(next_marker)
49    }
50}
51
52impl From<&str> for NextMarker {
53    fn from(next_marker: &str) -> Self {
54        Self::new(next_marker.to_owned())
55    }
56}