1use std::ops::Range;
2pub trait Slice<'s>: AsRef<str> + Clone + PartialEq {
3 fn slice(&self, range: Range<usize>) -> Self;
4 fn trim(&mut self);
5}
6
7impl<'s> Slice<'s> for String {
8 fn slice(&self, range: Range<usize>) -> Self {
9 self[range].to_string()
10 }
11
12 fn trim(&mut self) {
13 *self = self.trim_end().to_string();
14 }
15}
16
17impl<'s> Slice<'s> for &'s str {
18 fn slice(&self, range: Range<usize>) -> Self {
19 &self[range]
20 }
21
22 fn trim(&mut self) {
23 *self = self.trim_end();
24 }
25}
26