use std::ops::Range; pub trait Slice<'s>: AsRef + Clone + PartialEq { fn slice(&self, range: Range) -> Self; fn trim(&mut self); } impl<'s> Slice<'s> for String { fn slice(&self, range: Range) -> Self { self[range].to_string() } fn trim(&mut self) { *self = self.trim_end().to_string(); } } impl<'s> Slice<'s> for &'s str { fn slice(&self, range: Range) -> Self { &self[range] } fn trim(&mut self) { *self = self.trim_end(); } }