use std::ops::Index; struct Example(&'static [T]); impl Index for Example where F: FnOnce(usize) -> I, [T]: Index { type Output = <[T] as Index>::Output; fn index(&self, f: F) -> &Self::Output { &self.0[f(self.0.len())] } } fn main() { let my_slice = Example(&[1, 2, 3, 4]); println!("Prefix: {:?}", &my_slice[|n| ..(n/2)]); println!("Midpoint: {}", my_slice[|n| n/2]); println!("Suffix: {:?}", &my_slice[|n| (n/2)..]); }