palette to string function
This commit is contained in:
parent
46458e2506
commit
2e4d9fd36e
15
src/main.rs
15
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<String> = 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();
|
||||
|
|
Loading…
Reference in New Issue