Summary
Rust's standard library includes several implementations for basic things such as sorting or searching on its primitive slice type and the Iterator<T> trait. The slice type in particular has many highly important functions to offer.
binary_search() is a generic implementation of the binary search concepts provided on the slice type. Vec<T> can be quickly and easily (and implicitly) converted into a slice, making this a universally available function. However, it requires a sorting order to be present in the slice to work (and it won't fail if it's not) and, if custom types are used, an implementation of the Ord trait.
In case the slice cannot be sorted beforehand, the Iterator<T> variable's implementation of position() (of find() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access