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

Method format_bytes

crates/common/src/cformat.rs:411–433  ·  view source on GitHub ↗
(&self, bytes: &[u8])

Source from the content-addressed store, hash-verified

409 }
410
411 pub fn format_bytes(&self, bytes: &[u8]) -> Vec<u8> {
412 let bytes = if let Some(CFormatPrecision::Quantity(CFormatQuantity::Amount(precision))) =
413 self.precision
414 {
415 &bytes[..cmp::min(bytes.len(), precision)]
416 } else {
417 bytes
418 };
419 if let Some(CFormatQuantity::Amount(width)) = self.min_field_width {
420 let fill = cmp::max(0, width - bytes.len());
421 let mut v = Vec::with_capacity(bytes.len() + fill);
422 if self.flags.contains(CConversionFlags::LEFT_ADJUST) {
423 v.extend_from_slice(bytes);
424 v.append(&mut vec![b' '; fill]);
425 } else {
426 v.append(&mut vec![b' '; fill]);
427 v.extend_from_slice(bytes);
428 }
429 v
430 } else {
431 bytes.to_vec()
432 }
433 }
434
435 pub fn format_number(&self, num: &BigInt) -> String {
436 use CNumberType::*;

Callers 1

spec_format_bytesFunction · 0.80

Calls 6

minFunction · 0.85
maxFunction · 0.85
to_vecMethod · 0.80
lenMethod · 0.45
containsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected