Longest increasing subsequence algorithm
The parameter x doesn't have to be a Vec, it could be a slice instead (&amp;[i32]). However, if you had used a non-Copy item type (i32 is Copy), then in order to return individual items from the input Vec, you'd either have to clone the items or move them out of the Vec (using remove).
You've implemented binary search by hand, but the Rust standard library provides a very flexible implementation via slice::binary_search_by.


I present you my own implementation of the algorithm, based on a slightly different C++ implementation, which is why there are so many differences compared to your version. I wrote this about one year ago, but sadly, I no longer use it. Note a few things though that are not necessarily relevant to the code review:


This is a very generic function: the selector parameter is used to extract a particular field from each item in the slice. I was using this function on a slice of objects and I was interested in finding increasing values of a particular field of these objects.
The function returns indices into the slice, not the values themselves. I needed to know the indices of the items in the longest increasing subsequence because I had to do something else with the items that were not in the subsequence (without destroying the original sequence), and using indices was the easiest way to do that. If I wanted to return the values without consuming the original sequence, I could have returned a Vec of references to the items instead (Vec&lt;&amp;T&gt;).
Single letter variable names don't really help to understand the algorithm. Since I was using this algorithm for practical purposes, I took the time to understand and document it. If this is just an exercise to learn idiomatic Rust, I suppose this kind of detail doesn't matter much.
I like your use of a for loop on a reversed range iterator at the end. I should have done that myself!




/// Finds one of the [longest increasing subsequences][1]
/// from the subsequence created by applying `selector` on each item in `items`.
/// The result is a vector of indices within `items`
/// corresponding to one of the longest increasing subsequences.
///
/// [1]: https://en.wikipedia.org/wiki/Longest_increasing_subsequence
pub fn lis&lt;T, I: Ord, F: Fn(&amp;T) -&gt; I&gt;(items: &amp;[T], selector: F) -&gt; Vec&lt;usize&gt; {
    // This algorithm is adapted from
    // http://www.algorithmist.com/index.php?title=Longest_Increasing_Subsequence.cpp&amp;oldid=13595

    let mut result = Vec::new();

    // If `items` is empty, then the result is also empty.
    if items.is_empty() {
        return result;
    }

    // This vector stores, for each item,
    // the index of the largest item prior to itself that is smaller than itself.
    // We'll use this vector at the end to build the final result.
    let mut previous_chain = vec![0; items.len()];

    // Initially, we assume that the first item is part of the result.
    // We will replace this index later if that's not the case.
    result.push(0);

    for i in 1..items.len() {
        // If the next item is greater than the last item of the current longest subsequence,
        // push its index at the end of the result and continue.
        if selector(&amp;items[*result.last().unwrap()]) &lt; selector(&amp;items[i]) {
            previous_chain[i] = *result.last().unwrap();
            result.push(i);
            continue;
        }

        // Perform a binary search to find the index of an item in `result` to overwrite.
        // We want to overwrite an index that refers to the smallest item that is larger than `items[i]`.
        // If there is no such item, then we do nothing.
        let comparator = |&amp;result_index| {
            use std::cmp::Ordering;

            // We don't return Ordering::Equal when we find an equal value,
            // because we want to find the index of the first equal value.
            if selector(&amp;items[result_index]) &lt; selector(&amp;items[i]) {
                Ordering::Less
            } else {
                Ordering::Greater
            }
        };

        let next_element_index = match result.binary_search_by(comparator) {
            Ok(index) | Err(index) =&gt; index,
        };

        if selector(&amp;items[i]) &lt; selector(&amp;items[result[next_element_index]]) {
            if next_element_index &gt; 0 {
                previous_chain[i] = result[next_element_index - 1];
            }

            result[next_element_index] = i;
        }
    }

    // The last item in `result` is correct,
    // but we might have started overwriting earlier items
    // with what could have been a longer subsequence.
    // Walk back `previous_chain` to restore the proper subsequence.
    let mut u = result.len();
    let mut v = *result.last().unwrap();
    while u != 0 {
        u -= 1;
        result[u] = v;
        v = previous_chain[v];
    }

    result
}