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

Method index

crates/vm/src/protocol/sequence.rs:354–373  ·  view source on GitHub ↗
(&self, target: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

352 }
353
354 pub fn index(&self, target: &PyObject, vm: &VirtualMachine) -> PyResult<usize> {
355 let mut index: isize = -1;
356
357 let iter = self.obj.to_owned().get_iter(vm)?;
358 let iter = iter.iter::<PyObjectRef>(vm)?;
359
360 for elem in iter {
361 if index == isize::MAX {
362 return Err(vm.new_overflow_error("index exceeds C integer size"));
363 }
364 index += 1;
365
366 let elem = elem?;
367 if vm.bool_eq(&elem, target)? {
368 return Ok(index as usize);
369 }
370 }
371
372 Err(vm.new_value_error("sequence.index(x): x not in sequence"))
373 }
374
375 pub fn extract<F, R>(&self, mut f: F, vm: &VirtualMachine) -> PyResult<Vec<R>>
376 where

Callers

nothing calls this directly

Calls 4

get_iterMethod · 0.80
bool_eqMethod · 0.80
ErrClass · 0.50
to_ownedMethod · 0.45

Tested by

no test coverage detected