rust-selection-sort.kak/src/shuf.rs

15 lines
432 B
Rust
Raw Normal View History

2022-06-05 00:59:05 -04:00
use kakplugin::{get_selections, set_selections, KakError};
2022-02-21 18:30:32 -05:00
use rand::{seq::SliceRandom, thread_rng};
2022-02-21 17:23:34 -05:00
#[derive(clap::StructOpt, Debug)]
pub struct Options;
2022-06-05 00:59:05 -04:00
pub fn shuf(_options: &Options) -> Result<String, KakError> {
let mut selections = get_selections(None)?;
2022-02-21 17:23:34 -05:00
let mut rng = thread_rng();
selections.shuffle(&mut rng);
set_selections(selections.iter())?;
2022-02-21 17:23:34 -05:00
2022-06-05 00:59:05 -04:00
Ok(format!("Shuf {} selections", selections.len()))
2022-02-21 17:23:34 -05:00
}