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

Method format_string

crates/common/src/format.rs:835–854  ·  view source on GitHub ↗
(&self, s: &T)

Source from the content-addressed store, hash-verified

833 }
834
835 pub fn format_string<T>(&self, s: &T) -> Result<String, FormatSpecError>
836 where
837 T: CharLen + Deref<Target = str>,
838 {
839 self.validate_format(FormatType::String)?;
840 match self.format_type {
841 Some(FormatType::String) | None => self
842 .format_sign_and_align(s, "", FormatAlign::Left)
843 .map(|mut value| {
844 if let Some(precision) = self.precision {
845 value.truncate(precision);
846 }
847 value
848 }),
849 _ => {
850 let ch = char::from(self.format_type.as_ref().unwrap());
851 Err(FormatSpecError::UnknownFormatCode(ch, "str"))
852 }
853 }
854 }
855
856 pub fn format_complex(&self, num: &Complex64) -> Result<String, FormatSpecError> {
857 let (formatted_re, formatted_im) = self.format_complex_re_im(num)?;

Callers 7

_test_format_stringMethod · 0.45
test_percent_escapeMethod · 0.45
test_mappingMethod · 0.45
spec_format_stringFunction · 0.45
__format__Method · 0.45

Calls 7

validate_formatMethod · 0.80
format_sign_and_alignMethod · 0.80
ErrClass · 0.50
mapMethod · 0.45
truncateMethod · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45

Tested by 5

_test_format_stringMethod · 0.36
test_percent_escapeMethod · 0.36
test_mappingMethod · 0.36