Skip to content

Commit

Permalink
feat: make ContentType helper constructor const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Apr 3, 2024
1 parent 1b4efe2 commit b5827c2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/common/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,54 +44,54 @@ pub struct ContentType(Mime);
impl ContentType {
/// A constructor to easily create a `Content-Type: application/json` header.
#[inline]
pub fn json() -> ContentType {
pub const fn json() -> ContentType {
ContentType(mime::APPLICATION_JSON)
}

/// A constructor to easily create a `Content-Type: text/plain` header.
#[inline]
pub fn text() -> ContentType {
pub const fn text() -> ContentType {
ContentType(mime::TEXT_PLAIN)
}

/// A constructor to easily create a `Content-Type: text/plain; charset=utf-8` header.
#[inline]
pub fn text_utf8() -> ContentType {
pub const fn text_utf8() -> ContentType {
ContentType(mime::TEXT_PLAIN_UTF_8)
}

/// A constructor to easily create a `Content-Type: text/html` header.
#[inline]
pub fn html() -> ContentType {
pub const fn html() -> ContentType {
ContentType(mime::TEXT_HTML)
}

/// A constructor to easily create a `Content-Type: text/xml` header.
#[inline]
pub fn xml() -> ContentType {
pub const fn xml() -> ContentType {
ContentType(mime::TEXT_XML)
}

/// A constructor to easily create a `Content-Type: application/www-form-url-encoded` header.
#[inline]
pub fn form_url_encoded() -> ContentType {
pub const fn form_url_encoded() -> ContentType {
ContentType(mime::APPLICATION_WWW_FORM_URLENCODED)
}
/// A constructor to easily create a `Content-Type: image/jpeg` header.
#[inline]
pub fn jpeg() -> ContentType {
pub const fn jpeg() -> ContentType {
ContentType(mime::IMAGE_JPEG)
}

/// A constructor to easily create a `Content-Type: image/png` header.
#[inline]
pub fn png() -> ContentType {
pub const fn png() -> ContentType {
ContentType(mime::IMAGE_PNG)
}

/// A constructor to easily create a `Content-Type: application/octet-stream` header.
#[inline]
pub fn octet_stream() -> ContentType {
pub const fn octet_stream() -> ContentType {
ContentType(mime::APPLICATION_OCTET_STREAM)
}
}
Expand Down

0 comments on commit b5827c2

Please sign in to comment.