From 2e4d9fd36e13a8267f1884dcdffb7ee0a7c1e919 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sat, 11 Apr 2020 23:05:47 +0100 Subject: [PATCH] palette to string function --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index 34d7681..16d0c13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -517,6 +517,21 @@ fn test_palette_from_string_no_name() { assert_eq!(output, expected); } +fn palette_to_string(palette: Palette) -> String { + let name = if palette.name.is_some() { + format!("NAME {}\n", palette.name.unwrap()) + } else { + "".to_string() + }; + + let colours: Vec = palette.colours.into_iter().map(|colour| { + colour_to_string(colour) + }).collect(); + let colours = colours.join("\n"); + + format!("PAL {}\n{}{}", palette.id, name, colours) +} + fn position_from_string(string: String) -> Position { // e.g. "2,5" let xy: Vec<&str> = string.split(',').collect();