Moved to a more genral implementation for the response format.

This commit is contained in:
Slatian
2023-10-29 15:23:47 +01:00
parent 20fb7ee2ff
commit a33473fdc9
5 changed files with 143 additions and 37 deletions

View File

@ -1,38 +1,11 @@
use serde::{Deserialize,Serialize};
use std::sync::Arc;
use crate::mycelium::HtmlTextJsonFormat;
/* Response format */
#[derive(Deserialize, Serialize, Clone, Copy)]
pub enum ResponseFormat {
#[serde(rename="text/plain", alias="text")]
TextPlain,
#[serde(rename="text/html", alias="html")]
TextHtml,
#[serde(rename="application/json", alias="json")]
ApplicationJson,
}
impl ToString for ResponseFormat {
fn to_string(&self) -> String {
match self {
ResponseFormat::TextPlain => "text/plain",
ResponseFormat::TextHtml => "text/html",
ResponseFormat::ApplicationJson => "application/json",
}.to_string()
}
}
impl ResponseFormat {
pub fn to_file_extension(&self) -> String {
match self {
ResponseFormat::TextPlain => ".txt",
ResponseFormat::TextHtml => ".html",
ResponseFormat::ApplicationJson => ".json",
}.to_string()
}
}
pub type ResponseFormat = HtmlTextJsonFormat;
/* Query and Template Settings */