use crate::responses::ResponsesTypes;
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize)]
pub struct UnifiedTuple {
pub standard_code: u16,
pub standard_name: &'static str,
pub unified_description: &'static str,
pub internal_code: Option<u16>,
pub internal_name: Option<&'static str>,
}
impl UnifiedTuple {
pub fn as_json(&self) -> serde_json::Value {
serde_json::json!({
"standard http code": {
"code": self.standard_code,
"name": self.standard_name,
},
"description": self.unified_description,
"internal http code": {
"code": self.internal_code,
"name": self.internal_name,
},
})
}
pub fn new(
standard_code: u16,
standard_name: &'static str,
unified_description: &'static str,
internal_code: u16,
internal_name: &'static str,
) -> Self {
Self {
standard_code,
standard_name,
unified_description,
internal_code: Some(internal_code),
internal_name: Some(internal_name),
}
}
}
impl From<ResponsesTypes> for UnifiedTuple {
fn from(response: ResponsesTypes) -> Self {
let standard_code = response.get_code();
let standard_name = response.get_description();
let unified_description = response.get_description();
UnifiedTuple {
standard_code,
standard_name,
unified_description,
internal_code: None,
internal_name: None,
}
}
}