pub(crate) fn try_binary_search_range_by<K, F>(
range: Range<usize>,
target: &K,
key_extractor: F,
) -> Option<Result<usize, usize>>
Expand description
Performs a binary search over a range using a fallible key extraction function; a failed key extraction immediately terminats the search.
This is similar to the standard library’s binary_search_by
, but generalized to ranges instead
of slices.
§Arguments
range
- The range to search intarget
- The target value to search forkey_extractor
- A function that extracts a comparable key from slice elements. This function can fail and return None.
§Returns
Some(Ok(index))
- Element found at the given indexSome(Err(index))
- Element not found, but would be inserted at the given indexNone
- Key extraction failed