TryBinarySearch

Trait TryBinarySearch 

Source
pub trait TryBinarySearch<T> {
    // Required method
    fn try_binary_search_by<F>(
        &self,
        compare: F,
    ) -> OrderResult<Result<usize, usize>>
       where F: FnMut(&T) -> Option<Ordering>;

    // Provided methods
    fn try_binary_search(&self, x: &T) -> OrderResult<Result<usize, usize>>
       where T: PartialOrd<T> { ... }
    fn try_binary_search_by_key<K, F>(
        &self,
        b: &K,
        f: F,
    ) -> OrderResult<Result<usize, usize>>
       where F: FnMut(&T) -> Option<K>,
             K: PartialOrd<K> { ... }
}
Expand description

Binary Search methods for PartialOrd.

Caution! This might not return error even if there is invalid order value (like f32::NAN), because including these value means that it is not sorted correctly and we cannot ensure the return value of binary_search for unsorted slice.

Required Methods§

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> TryBinarySearch<T> for [T]

Source§

fn try_binary_search_by<F>( &self, compare: F, ) -> OrderResult<Result<usize, usize>>
where F: FnMut(&T) -> Option<Ordering>,

Implementors§