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

Method format_string_with_precision

crates/common/src/cformat.rs:377–396  ·  view source on GitHub ↗
(
        &self,
        string: T,
        precision: Option<&CFormatPrecision>,
    )

Source from the content-addressed store, hash-verified

375 }
376
377 fn format_string_with_precision<T: FormatBuf>(
378 &self,
379 string: T,
380 precision: Option<&CFormatPrecision>,
381 ) -> T {
382 // truncate if needed
383 let string = match precision {
384 Some(CFormatPrecision::Quantity(CFormatQuantity::Amount(precision)))
385 if string.chars().count() > *precision =>
386 {
387 string.chars().take(*precision).collect::<T>()
388 }
389 Some(CFormatPrecision::Dot) => {
390 // truncate to 0
391 T::default()
392 }
393 _ => string,
394 };
395 self.fill_string(string, b' '.into(), None)
396 }
397
398 #[inline]
399 pub fn format_string<T: FormatBuf>(&self, string: T) -> T {

Callers 2

format_stringMethod · 0.80
format_charMethod · 0.80

Calls 4

charsMethod · 0.80
fill_stringMethod · 0.80
countMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected