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

Function as_usize

crates/stdlib/src/bisect.rs:39–56  ·  view source on GitHub ↗
(
        lo: OptionalArg<ArgIndex>,
        hi: OptionalArg<ArgIndex>,
        seq_len: usize,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

37 // input sequence.
38 #[inline]
39 fn as_usize(
40 lo: OptionalArg<ArgIndex>,
41 hi: OptionalArg<ArgIndex>,
42 seq_len: usize,
43 vm: &VirtualMachine,
44 ) -> PyResult<(usize, usize)> {
45 // We only deal with positives for lo, try_from can't fail.
46 // Default is always a Some so we can safely unwrap.
47 let lo = handle_default(lo, vm)?
48 .map(|value| {
49 usize::try_from(value).map_err(|_| vm.new_value_error("lo must be non-negative"))
50 })
51 .unwrap_or(Ok(0))?;
52 let hi = handle_default(hi, vm)?
53 .map(|value| usize::try_from(value).unwrap_or(0))
54 .unwrap_or(seq_len);
55 Ok((lo, hi))
56 }
57
58 #[inline]
59 #[pyfunction]

Callers 2

bisect_leftFunction · 0.85
bisect_rightFunction · 0.85

Calls 2

handle_defaultFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected