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 {