add util functors for is_zero/is_equal; move clamp to math utils
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
bd75ff65c9
commit
63053640f1
3 changed files with 39 additions and 15 deletions
|
@ -14,8 +14,6 @@ pub mod sys;
|
|||
mod tests;
|
||||
pub mod time;
|
||||
|
||||
use std::cmp;
|
||||
|
||||
pub use ::ctor::{ctor, dtor};
|
||||
pub use algorithm::common_elements;
|
||||
pub use bytes::{increment, u64_from_bytes, u64_from_u8, u64_from_u8x8};
|
||||
|
@ -24,6 +22,7 @@ pub use debug::slice_truncated as debug_slice_truncated;
|
|||
pub use hash::calculate_hash;
|
||||
pub use html::Escape as HtmlEscape;
|
||||
pub use json::{deserialize_from_str, to_canonical_object};
|
||||
pub use math::clamp;
|
||||
pub use mutex_map::{Guard as MutexMapGuard, MutexMap};
|
||||
pub use rand::string as random_string;
|
||||
pub use string::{str_from_bytes, string_from_bytes};
|
||||
|
@ -31,14 +30,7 @@ pub use sys::available_parallelism;
|
|||
pub use time::now_millis as millis_since_unix_epoch;
|
||||
|
||||
#[inline]
|
||||
pub fn clamp<T: Ord>(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) }
|
||||
|
||||
#[inline]
|
||||
pub fn exchange<T: Clone>(state: &mut T, source: T) -> T {
|
||||
let ret = state.clone();
|
||||
*state = source;
|
||||
ret
|
||||
}
|
||||
pub fn exchange<T>(state: &mut T, source: T) -> T { std::mem::replace(state, source) }
|
||||
|
||||
#[must_use]
|
||||
pub fn generate_keypair() -> Vec<u8> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue