impl ColouredString {
pub fn plain(text: &str) -> Self {
ColouredString {
- text: text.to_string(),
+ text: text.to_owned(),
colour: " ".repeat(text.chars().count()),
}
}
pub fn uniform(text: &str, colour: char) -> Self {
ColouredString {
- text: text.to_string(),
+ text: text.to_owned(),
colour: colour.to_string().repeat(text.chars().count()),
}
}
assert_eq!(text.chars().count(), colour.chars().count(),
"Mismatched lengths in ColouredString::general");
ColouredString {
- text: text.to_string(),
- colour: colour.to_string(),
+ text: text.to_owned(),
+ colour: colour.to_owned(),
}
}
pub fn to_owned(&self) -> ColouredString {
ColouredString {
- text: self.text.to_string(),
- colour: self.colour.to_string(),
+ text: self.text.to_owned(),
+ colour: self.colour.to_owned(),
}
}
type Output = ColouredString;
fn add(self, rhs: ColouredString) -> ColouredString {
ColouredString {
- text: self.text.to_string() + &rhs.text,
- colour: self.colour.to_string() + &rhs.colour,
+ text: self.text.to_owned() + &rhs.text,
+ colour: self.colour.to_owned() + &rhs.colour,
}
}
}
type Output = ColouredString;
fn add(self, rhs: ColouredStringSlice<'_>) -> ColouredString {
ColouredString {
- text: self.text.to_string() + &rhs.text,
- colour: self.colour.to_string() + &rhs.colour,
+ text: self.text.to_owned() + &rhs.text,
+ colour: self.colour.to_owned() + &rhs.colour,
}
}
}
type Output = ColouredString;
fn add(self, rhs: ColouredString) -> ColouredString {
ColouredString {
- text: self.to_string() + &rhs.text,
+ text: self.to_owned() + &rhs.text,
colour: (" ".repeat(self.chars().count())) + &rhs.colour,
}
}
fn render(&self, width: usize) -> Vec<ColouredString> {
vec! {
ColouredString::uniform(
- &((&"-".repeat(width - min(2, width))).to_string() + "|"),
+ &((&"-".repeat(width - min(2, width))).to_owned() + "|"),
'-',
).truncate(width).to_owned(),
}
impl UsernameHeader {
pub fn from(account: &str, nameline: &str) -> Box<dyn TextFragment> {
Box::new(UsernameHeader{
- header: "From".to_string(),
+ header: "From".to_owned(),
colour: 'F',
- account: account.to_string(),
- nameline: nameline.to_string(),
+ account: account.to_owned(),
+ nameline: nameline.to_owned(),
})
}
pub fn via(account: &str, nameline: &str) -> Box<dyn TextFragment> {
Box::new(UsernameHeader{
- header: "Via".to_string(),
+ header: "Via".to_owned(),
colour: 'f',
- account: account.to_string(),
- nameline: nameline.to_string(),
+ account: account.to_owned(),
+ nameline: nameline.to_owned(),
})
}
}
tag == "body" {
// do nothing, except don't report this as an unknown tag
} else {
- self.bad_tags.insert(tag.to_string());
+ self.bad_tags.insert(tag.to_owned());
}
}
fn end_tag(&mut self, tag: &str, _attrs: &HashMap<String, String>) {
.collect();
trim_para_list(&mut paras);
Box::new(Media {
- url: url.to_string(),
+ url: url.to_owned(),
description: paras,
})
}
assert_eq!(fs.message, Some("hello, world".to_owned()));
let fsf = FileStatusLine::new()
- .add("A".to_string(), "Annoy", 10)
+ .add("A".to_owned(), "Annoy", 10)
.finalise();
assert_eq!(fsf.priwidth, vec! {
(10, 9),
});
let fsf = FileStatusLine::new()
- .add("A".to_string(), "Annoy", 10)
- .add("B".to_string(), "Badger", 10)
+ .add("A".to_owned(), "Annoy", 10)
+ .add("B".to_owned(), "Badger", 10)
.finalise();
assert_eq!(fsf.priwidth, vec! {
(10, 9 + 10 + FileStatusLine::SPACING),
});
let fsf = FileStatusLine::new()
- .add("A".to_string(), "Annoy", 10)
- .add("B".to_string(), "Badger", 5)
+ .add("A".to_owned(), "Annoy", 10)
+ .add("B".to_owned(), "Badger", 5)
.finalise();
assert_eq!(fsf.priwidth, vec! {
(10, 9),