From 3d1beca268e80f9d9ccdc0cf544727ebd4e9552a Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 12 Apr 2020 10:37:41 +0100 Subject: [PATCH] implement ToString for Dialogue --- src/main.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index bfe00da..e6b9e69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -982,19 +982,20 @@ fn test_dialogue_from_string() { ) } -fn dialogue_to_string(dialogue: Dialogue) -> String { - format!("DLG {}\n{}", dialogue.id, dialogue.contents) +impl ToString for Dialogue { + #[inline] + fn to_string(&self) -> String { + format!("DLG {}\n{}", self.id, self.contents) + } } #[test] fn test_dialogue_to_string() { assert_eq!( - dialogue_to_string( - Dialogue { - id: "y".to_string(), - contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string() - } - ), + Dialogue { + id: "y".to_string(), + contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string() + }.to_string(), "DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string() ); } @@ -1286,7 +1287,7 @@ fn game_to_string(game: Game) -> String { } for dialogue in game.dialogues { - segments.push(dialogue_to_string(dialogue)); + segments.push(dialogue.to_string()); } for ending in game.endings {