mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Rustfmt
This commit is contained in:
parent
158bc65c33
commit
51c6450688
@ -276,7 +276,8 @@ impl backend::Backend for Backend {
|
||||
"{}{}",
|
||||
termion::cursor::Goto(1 + pos.x as u16, 1 + pos.y as u16),
|
||||
text
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut dupes_left = repetitions - 1;
|
||||
while dupes_left > 0 {
|
||||
|
@ -390,7 +390,8 @@ impl<T: 'static> SelectView<T> {
|
||||
/// selection will likely be changed by the sorting.
|
||||
/// This sort is stable: items with identical label will not be reordered.
|
||||
pub fn sort_by_label(&mut self) {
|
||||
self.items.sort_by(|a, b| a.label.source().cmp(b.label.source()));
|
||||
self.items
|
||||
.sort_by(|a, b| a.label.source().cmp(b.label.source()));
|
||||
}
|
||||
|
||||
/// Sort the current items with the given comparator function.
|
||||
@ -401,7 +402,9 @@ impl<T: 'static> SelectView<T> {
|
||||
/// unspecified.
|
||||
/// This sort is stable: equal items will not be reordered.
|
||||
pub fn sort_by<F>(&mut self, mut compare: F)
|
||||
where F: FnMut(&T, &T) -> Ordering {
|
||||
where
|
||||
F: FnMut(&T, &T) -> Ordering,
|
||||
{
|
||||
self.items.sort_by(|a, b| compare(&a.value, &b.value));
|
||||
}
|
||||
|
||||
@ -410,7 +413,10 @@ impl<T: 'static> SelectView<T> {
|
||||
/// selection will likely be changed by the sorting.
|
||||
/// This sort is stable: items with equal keys will not be reordered.
|
||||
pub fn sort_by_key<K, F>(&mut self, mut key_of: F)
|
||||
where F: FnMut(&T) -> K, K: Ord {
|
||||
where
|
||||
F: FnMut(&T) -> K,
|
||||
K: Ord,
|
||||
{
|
||||
self.items.sort_by_key(|item| key_of(&item.value));
|
||||
}
|
||||
|
||||
@ -700,7 +706,10 @@ impl SelectView<String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> SelectView<T> where T: Ord {
|
||||
impl<T: 'static> SelectView<T>
|
||||
where
|
||||
T: Ord,
|
||||
{
|
||||
/// Sort the current items by their natural ordering.
|
||||
/// Note that this does not change the current focus index, which means that the current
|
||||
/// selection will likely be changed by the sorting.
|
||||
@ -877,13 +886,13 @@ mod tests {
|
||||
// We add items in no particular order, from going by their key value.
|
||||
#[derive(Eq, PartialEq, Debug)]
|
||||
struct MyStruct {
|
||||
key: i32
|
||||
key: i32,
|
||||
}
|
||||
|
||||
let mut view = SelectView::new();
|
||||
view.add_item("Y", MyStruct{ key: 2 });
|
||||
view.add_item("Z", MyStruct{ key: 1 });
|
||||
view.add_item("X", MyStruct{ key: 3 });
|
||||
view.add_item("Y", MyStruct { key: 2 });
|
||||
view.add_item("Z", MyStruct { key: 1 });
|
||||
view.add_item("X", MyStruct { key: 3 });
|
||||
|
||||
// Then sorting the list...
|
||||
view.sort_by_key(|s| s.key);
|
||||
|
Loading…
Reference in New Issue
Block a user