MCPcopy Index your code
hub / github.com/RustPython/RustPython / format_bool

Method format_bool

crates/common/src/format.rs:659–681  ·  view source on GitHub ↗
(&self, input: bool)

Source from the content-addressed store, hash-verified

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))?;

Callers 2

format_boolFunction · 0.80
__format__Method · 0.80

Calls 7

format_intMethod · 0.80
to_uppercaseMethod · 0.80
to_stringMethod · 0.80
ErrClass · 0.50
unwrapMethod · 0.45
format_floatMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected