use std::fmt::Display;
use auto_impl::auto_impl;
#[auto_impl(&, Box)]
trait DisplayCollection {
const LEN: Option<usize>;
type Out: Display;
fn display_at(&self, index: usize) -> Option<&Self::Out>;
}
impl<T: Display> DisplayCollection for Vec<T> {
type Out = T;
const LEN: Option<usize> = None;
fn display_at(&self, index: usize) -> Option<&Self::Out> {
self.get(index)
}
}
fn show_first(c: impl DisplayCollection) {
match c.display_at(0) {
Some(x) => println!("First: {}", x),
None => println!("Nothing :/"),
}
}
#[allow(clippy::needless_borrow)]
#[rustfmt::skip]
fn main() {
let v = vec!["dog", "cat"];
let boxed = Box::new(v.clone());
show_first(v.clone()); show_first(&v); show_first(&&v); show_first(boxed.clone()); show_first(&boxed); }