diff --git a/src/constraints.rs b/src/constraints.rs new file mode 100644 index 0000000..02ac2c3 --- /dev/null +++ b/src/constraints.rs @@ -0,0 +1,23 @@ +use std::os::raw::*; + +const MAX_BORDER_WIDTH: c_int = 10000; + +pub fn border_width(border_width: c_int) -> c_int { + if border_width > MAX_BORDER_WIDTH { return MAX_BORDER_WIDTH } + border_width +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_border_width() { + 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); + } +} diff --git a/src/lib.rs b/src/lib.rs index eba48aa..a80bb72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,24 +1,8 @@ +mod constraints; + use std::os::raw::*; -const MAX_BORDER_WIDTH: c_int = 10000; - #[no_mangle] -pub extern "C" fn constraints_border_width(border_width: c_int) -> c_int { - if border_width > MAX_BORDER_WIDTH { return MAX_BORDER_WIDTH } - border_width -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_constraints_border_width() { - assert_eq!(constraints_border_width(0), 0); - assert_eq!(constraints_border_width(10), 10); - assert_eq!(constraints_border_width(10_000), 10_000); - - assert_eq!(constraints_border_width(10_001), 10_000); - assert_eq!(constraints_border_width(20_000), 10_000); - } +extern "C" fn constraints_border_width(border_width: c_int) -> c_int { + constraints::border_width(border_width) }