You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
reverse/src/main.rs

45 lines
1.2 KiB

//#[inline]
fn reverse<T>(slice: &mut [T])
{
match slice {
[ref mut a, ref mut rest @ .., ref mut b] => {
std::mem::swap(a, b);
reverse(rest)
},
[] | [_] => (),
}
}
/// This actually works! And is so easily parallelisable with something like rayon, or asyncing by spawning/creating the tail-call into a new task, then either waiting them concurrently or in parallen (spawn or created future from just calling the function without awaiting it)
#[allow(dead_code)]
fn binsearch<'a, V: ?Sized, T: PartialEq<V> + 'a>(slice: &'a [T], find: &V) -> Option<&'a T>
{
match slice {
[ref a, pivot @ .., ref b] => {
match (a==find, b==find) {
(true, _) => Some(a),
(_, true) => Some(b),
_ => binsearch(pivot, find),
}
},
[ref a] if a == find => Some(a),
_ => None,
}
}
fn main() {
let mut args: Vec<String> = std::env::args().skip(1).collect();
reverse(&mut args[..]);
//eprintln!("{:?}", binsearch(&args[..], "1")); // It works!
#[cfg(feature="output-lines")]
{
for x in args.iter() {
#[cfg(feature="output-quoted")] println!("{:?}", x);
#[cfg(not(feature="output-quoted"))] println!("{}", x);
}
}
#[cfg(not(feature="output-lines"))]
println!("{:?}", args);
}