}
}
+impl<T: ColouredStringCommon> ColouredStringCommon for &'_ T {
+ fn text(&self) -> &str {
+ <T as ColouredStringCommon>::text(self)
+ }
+ fn colours(&self) -> &str {
+ <T as ColouredStringCommon>::colours(self)
+ }
+}
+
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColouredString {
text: String,
}
}
-impl<'a> ColouredStringCommon for &'a ColouredString {
- fn text(&self) -> &str {
- &self.text
- }
- fn colours(&self) -> &str {
- &self.colours
- }
-}
-
// I'd have liked here to write
// impl<T: ColouredStringCommon> From<T> for ColouredString { ... }
// on the basis that this code can sensibly make an owned ColouredString
}
}
-impl<'a> ColouredStringCommon for &ColouredStringSlice<'a> {
- fn text(&self) -> &str {
- self.text
- }
- fn colours(&self) -> &str {
- self.colours
- }
-}
-
impl<'a> ColouredStringSlice<'a> {
pub fn general(text: &'a str, colours: &'a str) -> Self {
assert_eq!(