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

Method extract

crates/vm/src/protocol/sequence.rs:375–394  ·  view source on GitHub ↗
(&self, mut f: F, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

373 }
374
375 pub fn extract<F, R>(&self, mut f: F, vm: &VirtualMachine) -> PyResult<Vec<R>>
376 where
377 F: FnMut(&PyObject) -> PyResult<R>,
378 {
379 if let Some(tuple) = self.obj.downcast_ref_if_exact::<PyTuple>(vm) {
380 tuple.iter().map(|x| f(x.as_ref())).collect()
381 } else if let Some(list) = self.obj.downcast_ref_if_exact::<PyList>(vm) {
382 list.borrow_vec().iter().map(|x| f(x.as_ref())).collect()
383 } else {
384 let iter = self.obj.to_owned().get_iter(vm)?;
385 let iter = iter.iter::<PyObjectRef>(vm)?;
386 let len = self.length(vm).unwrap_or(0);
387 let mut v = Vec::with_capacity(len);
388 for x in iter {
389 v.push(f(x?.as_ref())?);
390 }
391 v.shrink_to_fit();
392 Ok(v)
393 }
394 }
395
396 pub fn contains(self, target: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
397 if let Some(f) = self.slots().contains.load() {

Callers

nothing calls this directly

Calls 11

collectMethod · 0.80
borrow_vecMethod · 0.80
get_iterMethod · 0.80
shrink_to_fitMethod · 0.80
fFunction · 0.50
mapMethod · 0.45
iterMethod · 0.45
as_refMethod · 0.45
to_ownedMethod · 0.45
lengthMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected