add basic exchange util

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-23 06:57:14 +00:00
parent 5a17fbccf5
commit 91b49a7786

View file

@ -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();