css-colors icon indicating copy to clipboard operation
css-colors copied to clipboard

Add serde support

Open sergeysova opened this issue 7 years ago • 2 comments

What about to add serde support?

extern crate serde;
extern crate serde_json;
extern crate serde_derive;
extern crate css_colors;

use css_colors::{RGB, rgb};
use serde_derive::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct Example {
	color: RGB,
}

#[test]
fn example() {
	let example = Example {
		color: rgb(100, 200, 1),
	};

	let json = serde_json::to_string(&example).unwrap();
	
	assert!(json, "{\"color\":\"rgb(100,200,1)\"}");
}


sergeysova avatar Nov 20 '18 19:11 sergeysova

This would be a nice addition indeed, I could give it a try.

Best would be support of hex codes (in both short #abc and long #abcdef form) for RGB. The 8-hex version for RGBA is not standardised, but could be added as well.

franky47 avatar Feb 02 '19 20:02 franky47