From: Simon Tatham Date: Fri, 26 Jan 2024 07:26:33 +0000 (+0000) Subject: Move some ColouredString methods to the right file. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=2248b1622db9730b998a3e19b61c6503890d9e33;p=mastodonochrome.git Move some ColouredString methods to the right file. Just found these lying around in text.rs, apparently because they were useful for Paragraph. They should go with the rest of the ColouredString methods! In particular, is_space() ought to go in the trait shared between ColouredString{,Slice}, so that there only needs to be one of it. --- diff --git a/src/coloured_string.rs b/src/coloured_string.rs index e6a8b80..01221ca 100644 --- a/src/coloured_string.rs +++ b/src/coloured_string.rs @@ -60,6 +60,17 @@ pub trait ColouredStringCommon { fn recolour(&self, colour: char) -> ColouredString { ColouredString::uniform(self.text(), colour) } + + fn is_space(&self) -> bool { + if let Some(ch) = self.text().chars().next() { + ch == ' ' + } else { + false + } + } + fn is_colour(&self, colour: char) -> bool { + self.frags().all(|(_, c)| c == colour) + } } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/src/text.rs b/src/text.rs index 880c991..7b28033 100644 --- a/src/text.rs +++ b/src/text.rs @@ -474,30 +474,6 @@ pub struct Paragraph { centred: bool, } -impl ColouredString { - fn is_space(&self) -> bool { - if let Some(ch) = self.text().chars().next() { - ch == ' ' - } else { - false - } - } - - fn is_colour(&self, colour: char) -> bool { - self.frags().all(|(_, c)| c == colour) - } -} - -impl<'a> ColouredStringSlice<'a> { - fn is_space(&self) -> bool { - if let Some(ch) = self.text().chars().next() { - ch == ' ' - } else { - false - } - } -} - impl Paragraph { pub fn new() -> Self { Paragraph {