Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serde support #14

Open
sergeysova opened this issue Nov 20, 2018 · 2 comments
Open

Add serde support #14

sergeysova opened this issue Nov 20, 2018 · 2 comments

Comments

@sergeysova
Copy link

sergeysova commented Nov 20, 2018

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)\"}");
}
@franky47
Copy link

franky47 commented Feb 2, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@franky47 @sergeysova and others