Fix Rust code style
This commit is contained in:
parent
2d356cd473
commit
d49ff190d9
4 changed files with 123 additions and 95 deletions
1
Makefile
1
Makefile
|
@ -82,6 +82,7 @@ target/debug/libpolytreewm.a:
|
|||
test: $(TEST_EXE)
|
||||
@echo "$(TEST_EXE)" | awk '{ OFS="\n"; $$1=$$1 } 1' | /bin/sh
|
||||
$(CARGO) test
|
||||
$(CARGO) fmt --check
|
||||
|
||||
clean:
|
||||
rm -f $(ALL_OBJ) $(ALL_EXE)
|
||||
|
|
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
|
@ -0,0 +1 @@
|
|||
max_width = 80
|
|
@ -14,124 +14,142 @@ const MIN_SNAP_DISTANCE: c_uint = 1;
|
|||
const MAX_SNAP_DISTANCE: c_uint = 10000;
|
||||
|
||||
pub fn border_width(border_width: c_int) -> c_int {
|
||||
if border_width < MIN_BORDER_WIDTH { return MIN_BORDER_WIDTH }
|
||||
if border_width > MAX_BORDER_WIDTH { return MAX_BORDER_WIDTH }
|
||||
border_width
|
||||
if border_width < MIN_BORDER_WIDTH {
|
||||
return MIN_BORDER_WIDTH;
|
||||
}
|
||||
if border_width > MAX_BORDER_WIDTH {
|
||||
return MAX_BORDER_WIDTH;
|
||||
}
|
||||
border_width
|
||||
}
|
||||
|
||||
pub fn default_clients_in_master(default_clients_in_master: c_int) -> c_int {
|
||||
if default_clients_in_master < MIN_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MIN_DEFAULT_CLIENTS_IN_MASTER
|
||||
}
|
||||
if default_clients_in_master > MAX_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MAX_DEFAULT_CLIENTS_IN_MASTER
|
||||
}
|
||||
default_clients_in_master
|
||||
if default_clients_in_master < MIN_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MIN_DEFAULT_CLIENTS_IN_MASTER;
|
||||
}
|
||||
if default_clients_in_master > MAX_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MAX_DEFAULT_CLIENTS_IN_MASTER;
|
||||
}
|
||||
default_clients_in_master
|
||||
}
|
||||
|
||||
pub fn default_master_area_factor(default_master_area_factor: c_float) -> c_float {
|
||||
master_area_factor(default_master_area_factor)
|
||||
pub fn default_master_area_factor(
|
||||
default_master_area_factor: c_float,
|
||||
) -> c_float {
|
||||
master_area_factor(default_master_area_factor)
|
||||
}
|
||||
|
||||
pub fn gap_size(gap_size: c_int) -> c_int {
|
||||
if gap_size < MIN_GAP_SIZE { return MIN_GAP_SIZE }
|
||||
if gap_size > MAX_GAP_SIZE { return MAX_GAP_SIZE }
|
||||
gap_size
|
||||
if gap_size < MIN_GAP_SIZE {
|
||||
return MIN_GAP_SIZE;
|
||||
}
|
||||
if gap_size > MAX_GAP_SIZE {
|
||||
return MAX_GAP_SIZE;
|
||||
}
|
||||
gap_size
|
||||
}
|
||||
|
||||
pub fn master_area_factor(master_area_factor: c_float) -> c_float {
|
||||
if master_area_factor < MIN_MASTER_AREA_FACTOR { return MIN_MASTER_AREA_FACTOR }
|
||||
if master_area_factor > MAX_MASTER_AREA_FACTOR { return MAX_MASTER_AREA_FACTOR }
|
||||
master_area_factor
|
||||
if master_area_factor < MIN_MASTER_AREA_FACTOR {
|
||||
return MIN_MASTER_AREA_FACTOR;
|
||||
}
|
||||
if master_area_factor > MAX_MASTER_AREA_FACTOR {
|
||||
return MAX_MASTER_AREA_FACTOR;
|
||||
}
|
||||
master_area_factor
|
||||
}
|
||||
|
||||
pub fn max_clients_in_master(max_clients_in_master: c_int) -> c_int {
|
||||
if max_clients_in_master < MIN_MAX_CLIENTS_IN_MASTER {
|
||||
return MIN_MAX_CLIENTS_IN_MASTER
|
||||
}
|
||||
if max_clients_in_master > MAX_MAX_CLIENTS_IN_MASTER {
|
||||
return MAX_MAX_CLIENTS_IN_MASTER
|
||||
}
|
||||
max_clients_in_master
|
||||
if max_clients_in_master < MIN_MAX_CLIENTS_IN_MASTER {
|
||||
return MIN_MAX_CLIENTS_IN_MASTER;
|
||||
}
|
||||
if max_clients_in_master > MAX_MAX_CLIENTS_IN_MASTER {
|
||||
return MAX_MAX_CLIENTS_IN_MASTER;
|
||||
}
|
||||
max_clients_in_master
|
||||
}
|
||||
|
||||
pub fn snap_distance(snap_distance: c_uint) -> c_uint {
|
||||
if snap_distance < MIN_SNAP_DISTANCE { return MIN_SNAP_DISTANCE }
|
||||
if snap_distance > MAX_SNAP_DISTANCE { return MAX_SNAP_DISTANCE }
|
||||
snap_distance
|
||||
if snap_distance < MIN_SNAP_DISTANCE {
|
||||
return MIN_SNAP_DISTANCE;
|
||||
}
|
||||
if snap_distance > MAX_SNAP_DISTANCE {
|
||||
return MAX_SNAP_DISTANCE;
|
||||
}
|
||||
snap_distance
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_border_width() {
|
||||
assert_eq!(border_width(-1), 0);
|
||||
#[test]
|
||||
fn test_border_width() {
|
||||
assert_eq!(border_width(-1), 0);
|
||||
|
||||
assert_eq!(border_width(0), 0);
|
||||
assert_eq!(border_width(10), 10);
|
||||
assert_eq!(border_width(10_000), 10_000);
|
||||
assert_eq!(border_width(0), 0);
|
||||
assert_eq!(border_width(10), 10);
|
||||
assert_eq!(border_width(10_000), 10_000);
|
||||
|
||||
assert_eq!(border_width(10_001), 10_000);
|
||||
assert_eq!(border_width(20_000), 10_000);
|
||||
}
|
||||
assert_eq!(border_width(10_001), 10_000);
|
||||
assert_eq!(border_width(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_clients_in_master() {
|
||||
assert_eq!(default_clients_in_master(-1), 1);
|
||||
assert_eq!(default_clients_in_master(0), 1);
|
||||
#[test]
|
||||
fn test_default_clients_in_master() {
|
||||
assert_eq!(default_clients_in_master(-1), 1);
|
||||
assert_eq!(default_clients_in_master(0), 1);
|
||||
|
||||
assert_eq!(default_clients_in_master(1), 1);
|
||||
assert_eq!(default_clients_in_master(2), 2);
|
||||
assert_eq!(default_clients_in_master(9999), 9999);
|
||||
assert_eq!(default_clients_in_master(10_000), 10_000);
|
||||
assert_eq!(default_clients_in_master(1), 1);
|
||||
assert_eq!(default_clients_in_master(2), 2);
|
||||
assert_eq!(default_clients_in_master(9999), 9999);
|
||||
assert_eq!(default_clients_in_master(10_000), 10_000);
|
||||
|
||||
assert_eq!(default_clients_in_master(10_001), 10_000);
|
||||
assert_eq!(default_clients_in_master(20_000), 10_000);
|
||||
}
|
||||
assert_eq!(default_clients_in_master(10_001), 10_000);
|
||||
assert_eq!(default_clients_in_master(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gap_size() {
|
||||
assert_eq!(gap_size(-2), 0);
|
||||
assert_eq!(gap_size(-1), 0);
|
||||
#[test]
|
||||
fn test_gap_size() {
|
||||
assert_eq!(gap_size(-2), 0);
|
||||
assert_eq!(gap_size(-1), 0);
|
||||
|
||||
assert_eq!(gap_size(0), 0);
|
||||
assert_eq!(gap_size(1), 1);
|
||||
assert_eq!(gap_size(100), 100);
|
||||
assert_eq!(gap_size(9999), 9999);
|
||||
assert_eq!(gap_size(10_000), 10_000);
|
||||
assert_eq!(gap_size(0), 0);
|
||||
assert_eq!(gap_size(1), 1);
|
||||
assert_eq!(gap_size(100), 100);
|
||||
assert_eq!(gap_size(9999), 9999);
|
||||
assert_eq!(gap_size(10_000), 10_000);
|
||||
|
||||
assert_eq!(gap_size(10_001), 10_000);
|
||||
assert_eq!(gap_size(20_000), 10_000);
|
||||
}
|
||||
assert_eq!(gap_size(10_001), 10_000);
|
||||
assert_eq!(gap_size(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_max_clients_in_master() {
|
||||
assert_eq!(max_clients_in_master(-1), 1);
|
||||
assert_eq!(max_clients_in_master(0), 1);
|
||||
#[test]
|
||||
fn test_max_clients_in_master() {
|
||||
assert_eq!(max_clients_in_master(-1), 1);
|
||||
assert_eq!(max_clients_in_master(0), 1);
|
||||
|
||||
assert_eq!(max_clients_in_master(1), 1);
|
||||
assert_eq!(max_clients_in_master(2), 2);
|
||||
assert_eq!(max_clients_in_master(100), 100);
|
||||
assert_eq!(max_clients_in_master(9999), 9999);
|
||||
assert_eq!(max_clients_in_master(10_000), 10_000);
|
||||
assert_eq!(max_clients_in_master(1), 1);
|
||||
assert_eq!(max_clients_in_master(2), 2);
|
||||
assert_eq!(max_clients_in_master(100), 100);
|
||||
assert_eq!(max_clients_in_master(9999), 9999);
|
||||
assert_eq!(max_clients_in_master(10_000), 10_000);
|
||||
|
||||
assert_eq!(max_clients_in_master(10_001), 10_000);
|
||||
assert_eq!(max_clients_in_master(20_000), 10_000);
|
||||
}
|
||||
assert_eq!(max_clients_in_master(10_001), 10_000);
|
||||
assert_eq!(max_clients_in_master(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_snap_distance() {
|
||||
assert_eq!(snap_distance(0), 1);
|
||||
#[test]
|
||||
fn test_snap_distance() {
|
||||
assert_eq!(snap_distance(0), 1);
|
||||
|
||||
assert_eq!(snap_distance(1), 1);
|
||||
assert_eq!(snap_distance(2), 2);
|
||||
assert_eq!(snap_distance(100), 100);
|
||||
assert_eq!(snap_distance(9999), 9999);
|
||||
assert_eq!(snap_distance(10_000), 10_000);
|
||||
assert_eq!(snap_distance(1), 1);
|
||||
assert_eq!(snap_distance(2), 2);
|
||||
assert_eq!(snap_distance(100), 100);
|
||||
assert_eq!(snap_distance(9999), 9999);
|
||||
assert_eq!(snap_distance(10_000), 10_000);
|
||||
|
||||
assert_eq!(snap_distance(10_001), 10_000);
|
||||
assert_eq!(snap_distance(20_000), 10_000);
|
||||
}
|
||||
assert_eq!(snap_distance(10_001), 10_000);
|
||||
assert_eq!(snap_distance(20_000), 10_000);
|
||||
}
|
||||
}
|
||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -4,35 +4,43 @@ use std::os::raw::*;
|
|||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_border_width(border_width: c_int) -> c_int {
|
||||
constraints::border_width(border_width)
|
||||
constraints::border_width(border_width)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_default_clients_in_master(default_clients_in_master: c_int) -> c_int {
|
||||
constraints::default_clients_in_master(default_clients_in_master)
|
||||
extern "C" fn constraints_default_clients_in_master(
|
||||
default_clients_in_master: c_int,
|
||||
) -> c_int {
|
||||
constraints::default_clients_in_master(default_clients_in_master)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_default_master_area_factor(default_master_area_factor: c_float) -> c_float {
|
||||
constraints::default_master_area_factor(default_master_area_factor)
|
||||
extern "C" fn constraints_default_master_area_factor(
|
||||
default_master_area_factor: c_float,
|
||||
) -> c_float {
|
||||
constraints::default_master_area_factor(default_master_area_factor)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_gap_size(gap_size: c_int) -> c_int {
|
||||
constraints::gap_size(gap_size)
|
||||
constraints::gap_size(gap_size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_master_area_factor(master_area_factor: c_float) -> c_float {
|
||||
constraints::master_area_factor(master_area_factor)
|
||||
extern "C" fn constraints_master_area_factor(
|
||||
master_area_factor: c_float,
|
||||
) -> c_float {
|
||||
constraints::master_area_factor(master_area_factor)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_max_clients_in_master(max_clients_in_master: c_int) -> c_int {
|
||||
constraints::max_clients_in_master(max_clients_in_master)
|
||||
extern "C" fn constraints_max_clients_in_master(
|
||||
max_clients_in_master: c_int,
|
||||
) -> c_int {
|
||||
constraints::max_clients_in_master(max_clients_in_master)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_snap_distance(snap_distance: c_uint) -> c_uint {
|
||||
constraints::snap_distance(snap_distance)
|
||||
constraints::snap_distance(snap_distance)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue