(&self, input: bool)
| 657 | } |
| 658 | |
| 659 | pub fn format_bool(&self, input: bool) -> Result<String, FormatSpecError> { |
| 660 | let x = u8::from(input); |
| 661 | match &self.format_type { |
| 662 | Some( |
| 663 | FormatType::Binary |
| 664 | | FormatType::Decimal |
| 665 | | FormatType::Octal |
| 666 | | FormatType::Number(Case::Lower) |
| 667 | | FormatType::Hex(_) |
| 668 | | FormatType::GeneralFormat(_) |
| 669 | | FormatType::Character, |
| 670 | ) => self.format_int(&BigInt::from_u8(x).unwrap()), |
| 671 | Some(FormatType::Exponent(_) | FormatType::FixedPoint(_) | FormatType::Percentage) => { |
| 672 | self.format_float(x as f64) |
| 673 | } |
| 674 | None => { |
| 675 | let first_letter = (input.to_string().as_bytes()[0] as char).to_uppercase(); |
| 676 | Ok(first_letter.collect::<String>() + &input.to_string()[1..]) |
| 677 | } |
| 678 | Some(FormatType::Unknown(c)) => Err(FormatSpecError::UnknownFormatCode(*c, "int")), |
| 679 | _ => Err(FormatSpecError::InvalidFormatSpecifier), |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | pub fn format_float(&self, num: f64) -> Result<String, FormatSpecError> { |
| 684 | self.validate_format(FormatType::FixedPoint(Case::Lower))?; |
no test coverage detected