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

Method _contains

crates/vm/src/builtins/str.rs:611–620  ·  view source on GitHub ↗
(&self, needle: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

609 }
610
611 fn _contains(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
612 if let Some(needle) = needle.downcast_ref::<Self>() {
613 Ok(memchr::memmem::find(self.as_bytes(), needle.as_bytes()).is_some())
614 } else {
615 Err(vm.new_type_error(format!(
616 "'in <string>' requires string as left operand, not {}",
617 needle.class().name()
618 )))
619 }
620 }
621
622 fn __contains__(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool> {
623 self._contains(&needle, vm)

Callers 1

__contains__Method · 0.45

Calls 3

findFunction · 0.50
ErrClass · 0.50
as_bytesMethod · 0.45

Tested by

no test coverage detected