use std::cmp::Ordering::*; pub fn binary_search(data: &[T], target: &T) -> Option { let mut high = data.len(); let mut low = 0; let mut mid = high / 2; while low < high { match target.cmp(&data[mid]) { Less => high = mid - 1, Greater => low = mid + 1, Equal => return Some(mid), }; mid = (high + low) / 2; } None }