eio_okta_api/
query_string.rs1use std::ops::Deref;
2
3use iri_string::types::{UriQueryStr, UriQueryString};
4use serde::Serialize;
5
6#[derive(Debug, thiserror::Error)]
7#[remain::sorted]
8pub enum Error {
9 #[error("complex: {0}")]
10 Complex(#[from] serde_qs::Error),
11 #[error("invalid: {0}")]
12 Invalid(#[from] iri_string::validate::Error),
13 #[error("simple: {0}")]
14 Simple(#[from] serde_urlencoded::ser::Error),
15 #[error(transparent)]
16 Validation(#[from] validator::ValidationErrors),
17}
18
19pub struct QueryString(UriQueryString);
20
21impl Deref for QueryString {
22 type Target = UriQueryStr;
23 fn deref(&self) -> &Self::Target {
24 self.0.deref()
25 }
26}
27
28impl QueryString {
29 pub fn simple<T>(input: &T) -> Result<Self, Error>
30 where
31 T: Serialize,
32 {
33 let s = serde_urlencoded::to_string(input)?;
34 Ok(Self(UriQueryStr::new(&s)?.into()))
35 }
36
37 pub fn nested<T>(input: &T) -> Result<Self, Error>
38 where
39 T: Serialize,
40 {
41 let s = serde_qs::to_string(input)?;
42 Ok(Self(UriQueryStr::new(&s)?.into()))
43 }
44}