A better Rust ATProto crate
1

Configure Feed

Select the types of activity you want to include in your feed.

at main 910 B View raw
1#[cfg(not(feature = "js"))] 2pub type Duration = std::time::Duration; 3 4#[cfg(feature = "js")] 5pub type Duration = web_time::Duration; 6 7pub(crate) mod clock; 8 9pub(crate) use clock::Clock; 10 11/// a wrapper type over Instant to force checked additions and prevent 12/// unintentional overflow. The type preserve the Copy semantics for the wrapped 13#[derive(PartialEq, PartialOrd, Clone, Copy)] 14pub(crate) struct Instant(clock::Instant); 15 16pub(crate) trait CheckedTimeOps { 17 fn checked_add(&self, duration: Duration) -> Option<Self> 18 where 19 Self: Sized; 20} 21 22impl Instant { 23 pub(crate) fn new(instant: clock::Instant) -> Instant { 24 Instant(instant) 25 } 26 27 pub(crate) fn now() -> Instant { 28 Instant(clock::Instant::now()) 29 } 30} 31 32impl CheckedTimeOps for Instant { 33 fn checked_add(&self, duration: Duration) -> Option<Instant> { 34 self.0.checked_add(duration).map(Instant) 35 } 36}