pub struct ContentType {
pub type_: String,
pub subtype: String,
pub params: Vec<(String, String)>,
}Expand description
A structured Content-Type / media type value.
Stores the type/subtype pair plus an optional list of name=value
parameters. The Display implementation produces the
canonical wire format, e.g. application/json or
text/plain; charset=utf-8.
Fields§
§type_: StringThe primary type (e.g. "application").
subtype: StringThe subtype (e.g. "json").
params: Vec<(String, String)>Optional parameters such as charset or boundary.
Implementations§
Source§impl ContentType
impl ContentType
Sourcepub fn with_params(
type_: String,
subtype: String,
params: Vec<(String, String)>,
) -> Self
pub fn with_params( type_: String, subtype: String, params: Vec<(String, String)>, ) -> Self
Construct a ContentType with parameters.
Sourcepub fn essence(&self) -> String
pub fn essence(&self) -> String
Return the type/subtype string without parameters.
use api_bones::content_type::ContentType;
let ct = ContentType::text_plain_utf8();
assert_eq!(ct.essence(), "text/plain");Sourcepub fn param(&self, name: &str) -> Option<&str>
pub fn param(&self, name: &str) -> Option<&str>
Return the value of the named parameter, if present.
use api_bones::content_type::ContentType;
let ct = ContentType::text_plain_utf8();
assert_eq!(ct.param("charset"), Some("utf-8"));Sourcepub fn application_json() -> Self
pub fn application_json() -> Self
Returns application/json.
Sourcepub fn application_problem_json() -> Self
pub fn application_problem_json() -> Self
Returns application/problem+json (RFC 9457).
Sourcepub fn application_octet_stream() -> Self
pub fn application_octet_stream() -> Self
Returns application/octet-stream.
Sourcepub fn multipart_form_data(boundary: impl Into<String>) -> Self
pub fn multipart_form_data(boundary: impl Into<String>) -> Self
Returns multipart/form-data with the given boundary parameter.
Sourcepub fn text_plain() -> Self
pub fn text_plain() -> Self
Returns text/plain.
Sourcepub fn text_plain_utf8() -> Self
pub fn text_plain_utf8() -> Self
Returns text/plain; charset=utf-8.
Trait Implementations§
Source§impl Clone for ContentType
impl Clone for ContentType
Source§fn clone(&self) -> ContentType
fn clone(&self) -> ContentType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContentType
impl Debug for ContentType
Source§impl<'de> Deserialize<'de> for ContentType
Available on crate feature serde only.
impl<'de> Deserialize<'de> for ContentType
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for ContentType
impl Display for ContentType
Source§impl FromStr for ContentType
impl FromStr for ContentType
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse a Content-Type header value.
Accepts type/subtype with an optional ; name=value parameter list.
Parameter names are lowercased; values are kept as-is.
Source§type Err = ParseContentTypeError
type Err = ParseContentTypeError
Source§impl Hash for ContentType
impl Hash for ContentType
Source§impl PartialEq for ContentType
impl PartialEq for ContentType
Source§impl Serialize for ContentType
Available on crate feature serde only.
impl Serialize for ContentType
serde only.