Files
web-view/src/color.rs
Sam Green d5f9f284e3 Rewrite to use builder pattern. Fix dispatch unsafety. (#36)
* Major rewrite.

- Fix unsafety (require 'static bound on dispatched closure)
- Switch to builder pattern.
- Run rustfmt
- Fix clippy warnings
- Userdata borrowed from webview instead of being arg of dispatch closure
- Bump minor version
- Update webview
- Add crate-level doc

* Add rustfmt.toml

* Allow propagation of errors from invoke and dispatch closures.

* Refine doc comments.

* Add enum derives.

* Remove mut bound from `handle()`.

* Remove dependency on failure.
2018-11-10 20:16:12 +00:00

53 lines
982 B
Rust

/// An RGBA color.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl From<(u8, u8, u8, u8)> for Color {
fn from(tuple: (u8, u8, u8, u8)) -> Color {
Color {
r: tuple.0,
g: tuple.1,
b: tuple.2,
a: tuple.3,
}
}
}
impl From<(u8, u8, u8)> for Color {
fn from(tuple: (u8, u8, u8)) -> Color {
Color {
r: tuple.0,
g: tuple.1,
b: tuple.2,
a: 255,
}
}
}
impl From<[u8; 4]> for Color {
fn from(array: [u8; 4]) -> Color {
Color {
r: array[0],
g: array[1],
b: array[2],
a: array[3],
}
}
}
impl From<[u8; 3]> for Color {
fn from(array: [u8; 3]) -> Color {
Color {
r: array[0],
g: array[1],
b: array[2],
a: 255,
}
}
}