-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ralf Zerres <[email protected]>
- Loading branch information
Showing
7 changed files
with
157 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"_comment1": "The colour structure is an array of colour elements", | ||
"colour": [ | ||
{ | ||
"colour_name": "black", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [255,255,255,1], | ||
"hex": "000" | ||
} | ||
}, | ||
{ | ||
"colour_name": "white", | ||
"category": "value", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [0,0,0,1], | ||
"hex": "FFF" | ||
} | ||
}, | ||
{ | ||
"colour_name": "red", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [255,0,0,1], | ||
"hex": "FF0" | ||
} | ||
}, | ||
{ | ||
"colour_name": "blue", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [0,0,255,1], | ||
"hex": "00F" | ||
} | ||
}, | ||
{ | ||
"colour_name": "yellow", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [255,255,0,1], | ||
"hex": "FF0" | ||
} | ||
}, | ||
{ | ||
"colour_name": "green", | ||
"category": "hue", | ||
"colour_type": "Secondary", | ||
"code": { | ||
"rgba": [0,255,0,1], | ||
"hex": "0F0" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use serde::Deserialize; | ||
use serde_json::Result; | ||
use std::{ | ||
fs::File, | ||
io::BufReader, | ||
path::Path, | ||
}; | ||
|
||
// Valid color types | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub enum Type { | ||
/// Primery colour | ||
Primary, | ||
/// Secondary colour | ||
Secondary, | ||
} | ||
|
||
impl Default for Type { | ||
fn default() -> Self { Type::Primary } | ||
} | ||
|
||
// Color codes structure | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub struct Code { | ||
/// Color code as an rgba array | ||
pub rgba: Vec<u8>, | ||
/// Color code as a hex value | ||
pub hex: String, | ||
} | ||
|
||
// The colour structure | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub struct Colour { | ||
pub colour_name: String, | ||
pub category: String, | ||
pub colour_type: Type, | ||
pub code: Code, | ||
} | ||
|
||
// The colours structure | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub struct Colours { | ||
pub colour: Vec<Colour>, | ||
} | ||
|
||
pub fn read_colours<P>(path: P) -> Result<Colours> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
// Open the file in read-only mode with buffer | ||
let file = File::open(path).unwrap(); | ||
let reader = BufReader::new(file); | ||
|
||
// Read the JSON contents of the file as an instance of `Colours`. | ||
let colours: Colours = serde_json::from_reader(reader)?; | ||
|
||
// Return the `Colours` structure | ||
Ok(colours) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/// test import service | ||
pub mod twine_import; | ||
/// json import service | ||
pub mod json_import; |
This file was deleted.
Oops, something went wrong.