encoding_type: add Display implementation

This commit is contained in:
Matt Bilker
2018-12-03 20:39:12 +00:00
parent 6718e08579
commit ffb7a8e9ad

View File

@@ -1,3 +1,5 @@
use std::fmt;
use error::{KbinError, KbinErrorKind};
use failure::ResultExt;
@@ -24,6 +26,21 @@ impl Default for EncodingType {
}
}
impl fmt::Display for EncodingType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let encoding = match *self {
EncodingType::None => "None",
EncodingType::ASCII => "ASCII",
EncodingType::ISO_8859_1 => "ISO-8859-1",
EncodingType::EUC_JP => "EUC-JP",
EncodingType::SHIFT_JIS => "SHIFT-JIS",
EncodingType::UTF_8 => "UTF-8",
};
write!(f, "{}", encoding)
}
}
impl EncodingType {
pub fn from_byte(byte: u8) -> Result<Self, KbinError> {
let val = match byte {