pub enum ContentType {
ApplicationJson,
ApplicationXml,
TextPlain,
TextHtml,
FormUrlEncoded,
Unknown,
}
Expand description
Represents supported HTTP content types.
Variants§
ApplicationJson
application/json
ApplicationXml
application/xml
TextPlain
text/plain
TextHtml
text/html
FormUrlEncoded
application/x-www-form-urlencoded
Unknown
Unknown or unrecognized content type
Implementations§
Source§impl ContentType
impl ContentType
Sourcepub fn get_body_string<T: Serialize + Debug + Clone + Default + Display>(
&self,
data: &T,
) -> String
pub fn get_body_string<T: Serialize + Debug + Clone + Default + Display>( &self, data: &T, ) -> String
Public interface for getting a formatted body string based on the ContentType
.
This method routes the data to the appropriate handler method based on the
ContentType
, formatting the body accordingly.
§Type Parameters
T
: The type of the data to be formatted, which must implementSerialize
,Debug
,Clone
, andDefault
.
§Parameters
data
: The data to be formatted into the body string.
§Returns
A string containing the formatted body based on the content type, such as JSON, XML, plain text, HTML, etc.
Sourcepub fn format_content_type_with_charset(
content_type: &str,
charset: &str,
) -> String
pub fn format_content_type_with_charset( content_type: &str, charset: &str, ) -> String
Formats a content type with a charset value.
content_type
: The content type (e.g.,"text/html"
).charset
: The character set (e.g.,"utf-8"
).- Returns: A format string like
"text/html; charset=utf-8"
.
Sourcepub fn format_content_type_with_charset_declaration(
content_type: &str,
charset_with_key: &str,
) -> String
pub fn format_content_type_with_charset_declaration( content_type: &str, charset_with_key: &str, ) -> String
Formats a content type with a full charset declaration.
content_type
: The content type (e.g.,"text/html"
).charset_with_key
: The charset declaration (e.g.,"charset=utf-8"
).- Returns: A format string like
"text/html; charset=utf-8"
.
Trait Implementations§
Source§impl Clone for ContentType
impl Clone for ContentType
Source§fn clone(&self) -> ContentType
fn clone(&self) -> ContentType
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ContentType
impl Debug for ContentType
Source§impl Default for ContentType
impl Default for ContentType
Source§impl FromStr for ContentType
impl FromStr for ContentType
Source§impl PartialEq for ContentType
impl PartialEq for ContentType
impl Eq for ContentType
impl StructuralPartialEq for ContentType
Auto Trait Implementations§
impl Freeze for ContentType
impl RefUnwindSafe for ContentType
impl Send for ContentType
impl Sync for ContentType
impl Unpin for ContentType
impl UnwindSafe for ContentType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more