This adds a sort_by_key() function like the one in std, and a sort_by_file_name() function as a convenience for sorting by file name.
My experience with directory walkers in any languages I used so far was that mostly, I either don't care about the order, or I want an order that is deterministic for the same directory content independent from the underlying system. So if I need to sort, its almost always by file name.
This was my initial motivation for adding sort_by_key, to make sort_by(|a, b| a.file_name().cmp(b.file_name())) easier to write as sort_by_key(|e| e.file_name()). However, due to https://github.com/rust-lang/rust/issues/34162, this does not actually compile, so I also added sort_by_file_name() for what I perceive as the common case.
I kept sort_by_key() for consistency with std, and because there are still valid usecases for it, eg sorting by file size.
This adds a
sort_by_key()
function like the one instd
, and asort_by_file_name()
function as a convenience for sorting by file name.My experience with directory walkers in any languages I used so far was that mostly, I either don't care about the order, or I want an order that is deterministic for the same directory content independent from the underlying system. So if I need to sort, its almost always by file name.
This was my initial motivation for adding
sort_by_key
, to makesort_by(|a, b| a.file_name().cmp(b.file_name()))
easier to write assort_by_key(|e| e.file_name())
. However, due to https://github.com/rust-lang/rust/issues/34162, this does not actually compile, so I also addedsort_by_file_name()
for what I perceive as the common case.I kept
sort_by_key()
for consistency withstd
, and because there are still valid usecases for it, eg sorting by file size.