Skip to content

Commit b5827c2

Browse files
committed
feat: make ContentType helper constructor const fn
1 parent 1b4efe2 commit b5827c2

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/common/content_type.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,54 +44,54 @@ pub struct ContentType(Mime);
4444
impl ContentType {
4545
/// A constructor to easily create a `Content-Type: application/json` header.
4646
#[inline]
47-
pub fn json() -> ContentType {
47+
pub const fn json() -> ContentType {
4848
ContentType(mime::APPLICATION_JSON)
4949
}
5050

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

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

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

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

7575
/// A constructor to easily create a `Content-Type: application/www-form-url-encoded` header.
7676
#[inline]
77-
pub fn form_url_encoded() -> ContentType {
77+
pub const fn form_url_encoded() -> ContentType {
7878
ContentType(mime::APPLICATION_WWW_FORM_URLENCODED)
7979
}
8080
/// A constructor to easily create a `Content-Type: image/jpeg` header.
8181
#[inline]
82-
pub fn jpeg() -> ContentType {
82+
pub const fn jpeg() -> ContentType {
8383
ContentType(mime::IMAGE_JPEG)
8484
}
8585

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

9292
/// A constructor to easily create a `Content-Type: application/octet-stream` header.
9393
#[inline]
94-
pub fn octet_stream() -> ContentType {
94+
pub const fn octet_stream() -> ContentType {
9595
ContentType(mime::APPLICATION_OCTET_STREAM)
9696
}
9797
}

0 commit comments

Comments
 (0)