add clamp util.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-03-29 18:28:04 -07:00 committed by June
parent 4becbed2a7
commit 4a57592378

View file

@ -1,6 +1,7 @@
pub(crate) mod error;
use std::{
cmp,
cmp::Ordering,
fmt,
str::FromStr,
@ -14,6 +15,8 @@ use ruma::{canonical_json::try_from_json_map, CanonicalJsonError, CanonicalJsonO
use crate::{services, Error, Result};
pub(crate) fn clamp<T: Ord>(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) }
pub(crate) fn millis_since_unix_epoch() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)