#![allow(unused_qualifications)]
use crate::models;
#[cfg(any(feature = "client", feature = "server"))]
use crate::header;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct InlineObject {
#[serde(rename = "plainPassword")]
#[serde(skip_serializing_if="Option::is_none")]
pub plain_password: Option<String>,
}
impl InlineObject {
pub fn new() -> InlineObject {
InlineObject {
plain_password: None,
}
}
}
impl std::string::ToString for InlineObject {
fn to_string(&self) -> String {
let mut params: Vec<String> = vec![];
if let Some(ref plain_password) = self.plain_password {
params.push("plainPassword".to_string());
params.push(plain_password.to_string());
}
params.join(",").to_string()
}
}
impl std::str::FromStr for InlineObject {
type Err = String;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
#[derive(Default)]
struct IntermediateRep {
pub plain_password: Vec<String>,
}
let mut intermediate_rep = IntermediateRep::default();
let mut string_iter = s.split(',').into_iter();
let mut key_result = string_iter.next();
while key_result.is_some() {
let val = match string_iter.next() {
Some(x) => x,
None => return std::result::Result::Err("Missing value while parsing InlineObject".to_string())
};
if let Some(key) = key_result {
match key {
"plainPassword" => intermediate_rep.plain_password.push(<String as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?),
_ => return std::result::Result::Err("Unexpected key while parsing InlineObject".to_string())
}
}
key_result = string_iter.next();
}
std::result::Result::Ok(InlineObject {
plain_password: intermediate_rep.plain_password.into_iter().next(),
})
}
}
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<header::IntoHeaderValue<InlineObject>> for hyper::header::HeaderValue {
type Error = String;
fn try_from(hdr_value: header::IntoHeaderValue<InlineObject>) -> std::result::Result<Self, Self::Error> {
let hdr_value = hdr_value.to_string();
match hyper::header::HeaderValue::from_str(&hdr_value) {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(e) => std::result::Result::Err(
format!("Invalid header value for InlineObject - value: {} is invalid {}",
hdr_value, e))
}
}
}
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<InlineObject> {
type Error = String;
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
match hdr_value.to_str() {
std::result::Result::Ok(value) => {
match <InlineObject as std::str::FromStr>::from_str(value) {
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
std::result::Result::Err(err) => std::result::Result::Err(
format!("Unable to convert header value '{}' into InlineObject - {}",
value, err))
}
},
std::result::Result::Err(e) => std::result::Result::Err(
format!("Unable to convert header: {:?} to string: {}",
hdr_value, e))
}
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct User {
#[serde(rename = "id")]
#[serde(skip_serializing_if="Option::is_none")]
pub id: Option<uuid::Uuid>,
#[serde(rename = "username")]
pub username: String,
#[serde(rename = "email")]
#[serde(skip_serializing_if="Option::is_none")]
pub email: Option<String>,
#[serde(rename = "phone")]
#[serde(skip_serializing_if="Option::is_none")]
pub phone: Option<String>,
}
impl User {
pub fn new(username: String, ) -> User {
User {
id: None,
username: username,
email: None,
phone: None,
}
}
}
impl std::string::ToString for User {
fn to_string(&self) -> String {
let mut params: Vec<String> = vec![];
params.push("username".to_string());
params.push(self.username.to_string());
if let Some(ref email) = self.email {
params.push("email".to_string());
params.push(email.to_string());
}
if let Some(ref phone) = self.phone {
params.push("phone".to_string());
params.push(phone.to_string());
}
params.join(",").to_string()
}
}
impl std::str::FromStr for User {
type Err = String;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
#[derive(Default)]
struct IntermediateRep {
pub id: Vec<uuid::Uuid>,
pub username: Vec<String>,
pub email: Vec<String>,
pub phone: Vec<String>,
}
let mut intermediate_rep = IntermediateRep::default();
let mut string_iter = s.split(',').into_iter();
let mut key_result = string_iter.next();
while key_result.is_some() {
let val = match string_iter.next() {
Some(x) => x,
None => return std::result::Result::Err("Missing value while parsing User".to_string())
};
if let Some(key) = key_result {
match key {
"id" => intermediate_rep.id.push(<uuid::Uuid as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?),
"username" => intermediate_rep.username.push(<String as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?),
"email" => intermediate_rep.email.push(<String as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?),
"phone" => intermediate_rep.phone.push(<String as std::str::FromStr>::from_str(val).map_err(|x| format!("{}", x))?),
_ => return std::result::Result::Err("Unexpected key while parsing User".to_string())
}
}
key_result = string_iter.next();
}
std::result::Result::Ok(User {
id: intermediate_rep.id.into_iter().next(),
username: intermediate_rep.username.into_iter().next().ok_or("username missing in User".to_string())?,
email: intermediate_rep.email.into_iter().next(),
phone: intermediate_rep.phone.into_iter().next(),
})
}
}
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<header::IntoHeaderValue<User>> for hyper::header::HeaderValue {
type Error = String;
fn try_from(hdr_value: header::IntoHeaderValue<User>) -> std::result::Result<Self, Self::Error> {
let hdr_value = hdr_value.to_string();
match hyper::header::HeaderValue::from_str(&hdr_value) {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(e) => std::result::Result::Err(
format!("Invalid header value for User - value: {} is invalid {}",
hdr_value, e))
}
}
}
#[cfg(any(feature = "client", feature = "server"))]
impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderValue<User> {
type Error = String;
fn try_from(hdr_value: hyper::header::HeaderValue) -> std::result::Result<Self, Self::Error> {
match hdr_value.to_str() {
std::result::Result::Ok(value) => {
match <User as std::str::FromStr>::from_str(value) {
std::result::Result::Ok(value) => std::result::Result::Ok(header::IntoHeaderValue(value)),
std::result::Result::Err(err) => std::result::Result::Err(
format!("Unable to convert header value '{}' into User - {}",
value, err))
}
},
std::result::Result::Err(e) => std::result::Result::Err(
format!("Unable to convert header: {:?} to string: {}",
hdr_value, e))
}
}
}