Equivalent to PySlice_Unpack.
(slice: &PySlice, vm: &VirtualMachine)
| 349 | impl SaturatedSlice { |
| 350 | // Equivalent to PySlice_Unpack. |
| 351 | pub fn with_slice(slice: &PySlice, vm: &VirtualMachine) -> PyResult<Self> { |
| 352 | let step = to_isize_index(vm, slice.step_ref(vm))?.unwrap_or(1); |
| 353 | if step == 0 { |
| 354 | return Err(vm.new_value_error("slice step cannot be zero")); |
| 355 | } |
| 356 | let start = to_isize_index(vm, slice.start_ref(vm))? |
| 357 | .unwrap_or_else(|| if step.is_negative() { isize::MAX } else { 0 }); |
| 358 | |
| 359 | let stop = to_isize_index(vm, &slice.stop(vm))?.unwrap_or_else(|| { |
| 360 | if step.is_negative() { |
| 361 | isize::MIN |
| 362 | } else { |
| 363 | isize::MAX |
| 364 | } |
| 365 | }); |
| 366 | Ok(Self { start, stop, step }) |
| 367 | } |
| 368 | |
| 369 | // Equivalent to PySlice_AdjustIndices |
| 370 | /// Convert for usage in indexing the underlying rust collections. Called *after* |
nothing calls this directly
no test coverage detected