refactor: remove discriminant method

This commit is contained in:
Ashley Wulber 2024-03-25 16:04:12 -04:00
parent f5908d028a
commit 9a0816b140
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820

View file

@ -69,16 +69,7 @@ impl AsRef<str> for MimeType {
fn as_ref(&self) -> &str {
match self {
MimeType::Other(s) => s.as_ref(),
m => ALLOWED_TEXT_MIME_TYPES[m.discriminant()],
}
}
}
impl MimeType {
fn discriminant(&self) -> usize {
match self {
MimeType::Text(t) => *t as usize,
MimeType::Other(_) => 3,
MimeType::Text(text) => ALLOWED_TEXT_MIME_TYPES[*text as usize],
}
}
}
@ -123,7 +114,7 @@ impl std::fmt::Display for MimeType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MimeType::Other(m) => write!(f, "{}", m),
m => write!(f, "{}", ALLOWED_TEXT_MIME_TYPES[m.discriminant()]),
MimeType::Text(text) => write!(f, "{}", ALLOWED_TEXT_MIME_TYPES[*text as usize]),
}
}
}