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

Method py_partition

crates/vm/src/anystr.rs:321–343  ·  view source on GitHub ↗
(
        &'a self,
        sub: &Self,
        split: F,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

319 }
320
321 fn py_partition<'a, F, S>(
322 &'a self,
323 sub: &Self,
324 split: F,
325 vm: &VirtualMachine,
326 ) -> PyResult<(Self::Container, bool, Self::Container)>
327 where
328 F: Fn() -> S,
329 S: core::iter::Iterator<Item = &'a Self>,
330 {
331 if sub.is_empty() {
332 return Err(vm.new_value_error("empty separator"));
333 }
334
335 let mut sp = split();
336 let front = sp.next().unwrap().to_container();
337 let (has_mid, back) = if let Some(back) = sp.next() {
338 (true, back.to_container())
339 } else {
340 (false, Self::Container::new())
341 };
342 Ok((front, has_mid, back))
343 }
344
345 fn py_removeprefix<FC>(&self, prefix: &Self, prefix_len: usize, is_prefix: FC) -> &Self
346 where

Callers 4

partitionMethod · 0.80
rpartitionMethod · 0.80
partitionMethod · 0.80
rpartitionMethod · 0.80

Implementers 2

bytes_inner.rscrates/vm/src/bytes_inner.rs
str.rscrates/vm/src/builtins/str.rs

Calls 7

newFunction · 0.85
ErrClass · 0.50
splitFunction · 0.50
is_emptyMethod · 0.45
to_containerMethod · 0.45
unwrapMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected