Skip to content

Commit e11cda9

Browse files
committed
Implement From trait
1 parent 478aa41 commit e11cda9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

common/src/format.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ pub enum FormatType {
137137
Percentage,
138138
}
139139

140+
impl From<&FormatType> for char {
141+
fn from(from: &FormatType) -> char {
142+
match from {
143+
FormatType::String => 's',
144+
FormatType::Binary => 'b',
145+
FormatType::Character => 'c',
146+
FormatType::Decimal => 'd',
147+
FormatType::Octal => 'o',
148+
FormatType::HexLower => 'x',
149+
FormatType::HexUpper => 'X',
150+
FormatType::Number => 'n',
151+
FormatType::ExponentLower => 'e',
152+
FormatType::ExponentUpper => 'E',
153+
FormatType::GeneralFormatLower => 'g',
154+
FormatType::GeneralFormatUpper => 'G',
155+
FormatType::FixedPointLower => 'f',
156+
FormatType::FixedPointUpper => 'F',
157+
FormatType::Percentage => '%',
158+
}
159+
}
160+
}
161+
140162
impl FormatParse for FormatType {
141163
fn parse(text: &str) -> (Option<Self>, &str) {
142164
let mut chars = text.chars();

0 commit comments

Comments
 (0)