aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-12-29 20:39:30 -0500
committerJoe Wilm <joe@jwilm.com>2016-12-29 20:53:41 -0500
commitb704dafb2420df6f7fca64980a2f52c1a00bcef5 (patch)
treef4659fa9ba38a8626d478e23d97b331c6dd5f8dc /src/util.rs
parentf1336ee1c74c8e3d324ff7b32b562a64046df5ce (diff)
downloadalacritty-b704dafb2420df6f7fca64980a2f52c1a00bcef5.tar.gz
alacritty-b704dafb2420df6f7fca64980a2f52c1a00bcef5.zip
Fix some bugs with selections
Moving the window on macOS would cause a panic in certain circumstances.
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/util.rs b/src/util.rs
index a5a4807e..cd8bc9a1 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -11,7 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-//
+use std::cmp;
+
/// Threading utilities
pub mod thread {
/// Like `thread::spawn`, but with a `name` argument
@@ -29,3 +30,19 @@ pub mod thread {
pub use ::std::thread::*;
}
+
+pub fn limit<T: Ord>(value: T, min: T, max: T) -> T {
+ cmp::min(cmp::max(value, min), max)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::limit;
+
+ #[test]
+ fn limit_works() {
+ assert_eq!(10, limit(10, 0, 100));
+ assert_eq!(10, limit(5, 10, 100));
+ assert_eq!(100, limit(1000, 10, 100));
+ }
+}