Implement From trait

This commit is contained in:
yt2b committed 2023-01-03 16:08:41 +09:00
1 parent 478aa41cc6
commit e11cda970a
1 file changed
+22
+22
View File
@@ -137,6 +137,28 @@ pub enum FormatType {
Percentage,
}
impl From<&FormatType> for char {
fn from(from: &FormatType) -> char {
match from {
FormatType::String => 's',
FormatType::Binary => 'b',
FormatType::Character => 'c',
FormatType::Decimal => 'd',
FormatType::Octal => 'o',
FormatType::HexLower => 'x',
FormatType::HexUpper => 'X',
FormatType::Number => 'n',
FormatType::ExponentLower => 'e',
FormatType::ExponentUpper => 'E',
FormatType::GeneralFormatLower => 'g',
FormatType::GeneralFormatUpper => 'G',
FormatType::FixedPointLower => 'f',
FormatType::FixedPointUpper => 'F',
FormatType::Percentage => '%',
}
}
}
impl FormatParse for FormatType {
fn parse(text: &str) -> (Option<Self>, &str) {
let mut chars = text.chars();