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

Method _pad

crates/vm/src/builtins/str.rs:1296–1313  ·  view source on GitHub ↗
(
        &self,
        width: isize,
        fillchar: OptionalArg<PyStrRef>,
        pad: fn(&Wtf8, usize, CodePoint, usize) -> Wtf8Buf,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

1294
1295 #[inline]
1296 fn _pad(
1297 &self,
1298 width: isize,
1299 fillchar: OptionalArg<PyStrRef>,
1300 pad: fn(&Wtf8, usize, CodePoint, usize) -> Wtf8Buf,
1301 vm: &VirtualMachine,
1302 ) -> PyResult<Wtf8Buf> {
1303 let fillchar = fillchar.map_or(Ok(' '.into()), |ref s| {
1304 s.as_wtf8().code_points().exactly_one().map_err(|_| {
1305 vm.new_type_error("The fill character must be exactly one character long")
1306 })
1307 })?;
1308 Ok(if self.len() as isize >= width {
1309 self.as_wtf8().to_owned()
1310 } else {
1311 pad(self.as_wtf8(), width as usize, fillchar, self.len())
1312 })
1313 }
1314
1315 #[pymethod]
1316 fn center(

Callers 3

centerMethod · 0.45
ljustMethod · 0.45
rjustMethod · 0.45

Calls 4

code_pointsMethod · 0.80
as_wtf8Method · 0.45
lenMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected