-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from barkanido/handle-ttl-overflow
protect overflow when computing expiration
- Loading branch information
Showing
11 changed files
with
167 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::time::Duration; | ||
|
||
pub(crate) type Clock = quanta::Clock; | ||
#[cfg(test)] | ||
pub(crate) type Mock = quanta::Mock; | ||
|
||
/// a wrapper type over qunta::Instant to force checked additions and prevent | ||
/// unintentioal overflow. The type preserve the Copy semnatics for the wrapped | ||
#[derive(PartialEq, PartialOrd, Clone, Copy)] | ||
pub(crate) struct Instant(pub quanta::Instant); | ||
|
||
pub(crate) trait CheckedTimeOps { | ||
fn checked_add(&self, duration: Duration)-> Option<Self> where Self: Sized; | ||
} | ||
|
||
impl Instant { | ||
pub(crate) fn new(instant: quanta::Instant) -> Instant { | ||
Instant(instant) | ||
} | ||
|
||
pub(crate) fn now()-> Instant { | ||
Instant(quanta::Instant::now()) | ||
} | ||
} | ||
|
||
impl CheckedTimeOps for Instant { | ||
fn checked_add(&self, duration: Duration) -> Option<Instant> { | ||
self.0.checked_add(duration).map(Instant) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters