implement From for Colour
This commit is contained in:
parent
7b941b5d99
commit
b09b9dbece
10
src/main.rs
10
src/main.rs
|
@ -589,8 +589,9 @@ fn test_tile_to_string() {
|
|||
assert_eq!(output, expected);
|
||||
}
|
||||
|
||||
fn colour_from_string(colour: String) -> Colour {
|
||||
let values: Vec<&str> = colour.split(',').collect();
|
||||
impl From<String> for Colour {
|
||||
fn from(string: String) -> Colour {
|
||||
let values: Vec<&str> = string.split(',').collect();
|
||||
|
||||
let red: u8 = values[0].parse().unwrap_or(0);
|
||||
let green: u8 = values[1].parse().unwrap_or(0);
|
||||
|
@ -598,11 +599,12 @@ fn colour_from_string(colour: String) -> Colour {
|
|||
|
||||
Colour { red, green, blue }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_colour_from_string() {
|
||||
assert_eq!(
|
||||
colour_from_string("0,255,0".to_string()),
|
||||
Colour::from("0,255,0".to_string()),
|
||||
Colour { red: 0, green: 255, blue: 0 }
|
||||
);
|
||||
}
|
||||
|
@ -635,7 +637,7 @@ fn palette_from_string(palette: String) -> Palette {
|
|||
let colour_start_index = if name.is_some() {2} else {1};
|
||||
|
||||
let colours = lines[colour_start_index..].iter().map(|&line| {
|
||||
colour_from_string(line.to_string())
|
||||
Colour::from(line.to_string())
|
||||
}).collect();
|
||||
|
||||
Palette { id, name, colours }
|
||||
|
|
Loading…
Reference in New Issue