What is a good way to build a string from
- some string literals and
- some struct fields?
impl MyType{
pub fn return_a_string(self: Self)->String {
let mut out = String::new();
//out.push_str(&self.position.0.to_string());
//out.push_str(&self.position.1.to_string());
out.push_str(" (GmmiTextObject");
out.push_str(" (GmmiObject \"\" 0");
out.push_str(" MORE TEXT ");
<SNIP>
out.push_str(&self.name); // my data
out.push_str("\" 0)");
out
}
}
I call this function in a loop and write it to a text file using write!
for data in &self.data {
write!(output, "{:?}\r\n", data.return_a_string());
}
The problem is:
- It is all on one line (I tried adding \r\n but it just prints it out)
- It gets a " in front of each line
" (GmmiTextObject (GmmiObject \"\" 0 (Help \"\" \"\" \"\") (GmmiOptionTable <SNIP> (Point 2520 4500) \"EQUIPMENT\" 0)"