add basic exchange util
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
5a17fbccf5
commit
91b49a7786
1 changed files with 8 additions and 0 deletions
|
@ -26,8 +26,16 @@ pub use string::{str_from_bytes, string_from_bytes};
|
|||
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
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn generate_keypair() -> Vec<u8> {
|
||||
let mut value = rand::string(8).as_bytes().to_vec();
|
||||
|
|
Loading…
Add table
Reference in a new issue