Skip to content

Commit

Permalink
Add cargo fmt configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 committed Jan 29, 2022
1 parent eef25ed commit 7018756
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
18 changes: 18 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
binop_separator = "Back"
blank_lines_lower_bound = 0
blank_lines_upper_bound = 3
brace_style = "PreferSameLine"
color = "Auto"
condense_wildcard_suffixes = true
fn_single_line = true
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
max_width = 80
newline_style = "Unix"
normalize_doc_attributes = true
overflow_delimited_expr = true
reorder_imports = true
reorder_modules = true
use_field_init_shorthand = true
use_try_shorthand = true
4 changes: 1 addition & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate cc;

fn main() {
cc::Build::new().file("src/ansi256.c").compile("ansi256");
}
fn main() { cc::Build::new().file("src/ansi256.c").compile("ansi256"); }
16 changes: 4 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ pub trait AsRGB {

/// Representation of an RGB colour as 24-bit `0xRRGGBB` integer.
impl AsRGB for u32 {
fn as_u32(&self) -> u32 {
*self
}
fn as_u32(&self) -> u32 { *self }
}

#[inline]
Expand All @@ -131,19 +129,13 @@ fn to_u32(r: u8, g: u8, b: u8) -> u32 {
}

impl AsRGB for (u8, u8, u8) {
fn as_u32(&self) -> u32 {
to_u32(self.0, self.1, self.2)
}
fn as_u32(&self) -> u32 { to_u32(self.0, self.1, self.2) }
}

impl AsRGB for [u8; 3] {
fn as_u32(&self) -> u32 {
to_u32(self[0], self[1], self[2])
}
fn as_u32(&self) -> u32 { to_u32(self[0], self[1], self[2]) }
}

impl<'a, T: AsRGB + ?Sized> AsRGB for &'a T {
fn as_u32(&self) -> u32 {
(*self).as_u32()
}
fn as_u32(&self) -> u32 { (*self).as_u32() }
}
11 changes: 4 additions & 7 deletions tests/ansi256.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
fn to_rgb(index: u8) -> (u8, u8, u8) {
ansi_colours::rgb_from_ansi256(index)
}
fn to_rgb(index: u8) -> (u8, u8, u8) { ansi_colours::rgb_from_ansi256(index) }

fn to_ansi(rgb: (u8, u8, u8)) -> u8 {
ansi_colours::ansi256_from_rgb(rgb)
}
fn to_ansi(rgb: (u8, u8, u8)) -> u8 { ansi_colours::ansi256_from_rgb(rgb) }

static CUBE_VALUES: [u8; 6] = [0, 95, 135, 175, 215, 255];

Expand Down Expand Up @@ -52,7 +48,8 @@ fn best_grey(y: u8) -> u8 {
.map(|(idx, v)| (*v, idx as u8 * (36 + 6 + 1) + 16))
.chain((0..24u8).map(|idx| (idx * 10 + 8, idx + 232)))
.fold((f32::INFINITY, 0), |best, elem| {
let d = empfindung::de2000::diff_rgb(&grey, &[elem.0, elem.0, elem.0]);
let d =
empfindung::de2000::diff_rgb(&grey, &[elem.0, elem.0, elem.0]);
if d < best.0 {
(d, elem.1)
} else {
Expand Down

0 comments on commit 7018756

Please sign in to comment.