Skip to content

Commit b8a9325

Browse files
committed
Use improved Duration constructors and const fn
1 parent ce9cc49 commit b8a9325

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

ui/src/main.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ mod gist;
3838
mod sandbox;
3939

4040
const ONE_HOUR_IN_SECONDS: u32 = 60 * 60;
41-
const ONE_DAY_IN_SECONDS: u64 = 60 * 60 * 24;
42-
const ONE_YEAR_IN_SECONDS: u64 = 60 * 60 * 24 * 365;
41+
const ONE_HOUR: Duration = Duration::from_secs(ONE_HOUR_IN_SECONDS as u64);
42+
const ONE_DAY: Duration = Duration::from_secs(60 * 60 * 24);
43+
const ONE_YEAR: Duration = Duration::from_secs(60 * 60 * 24 * 365);
4344

44-
const SANDBOX_CACHE_TIME_TO_LIVE_IN_SECONDS: u64 = ONE_HOUR_IN_SECONDS as u64;
45+
const SANDBOX_CACHE_TIME_TO_LIVE: Duration = ONE_HOUR;
4546

4647
fn main() {
4748
// Dotenv may be unable to load environment variables, but that's ok in production
@@ -66,11 +67,9 @@ fn main() {
6667

6768
let files = Staticfile::new(&root).expect("Unable to open root directory");
6869
let mut files = Chain::new(files);
69-
let one_day = Duration::new(ONE_DAY_IN_SECONDS, 0);
70-
let one_year = Duration::new(ONE_YEAR_IN_SECONDS, 0);
7170

72-
files.link_after(ModifyWith::new(Cache::new(one_day)));
73-
files.link_after(Prefix::new(&["assets"], Cache::new(one_year)));
71+
files.link_after(ModifyWith::new(Cache::new(ONE_DAY)));
72+
files.link_after(Prefix::new(&["assets"], Cache::new(ONE_YEAR)));
7473
files.link_after(GuessContentType::new(ContentType::html().0));
7574

7675
let mut gist_router = Router::new();
@@ -436,9 +435,7 @@ where
436435

437436
match cache.clone() {
438437
Some(cached) => {
439-
if cached.time.elapsed()
440-
> Duration::from_secs(SANDBOX_CACHE_TIME_TO_LIVE_IN_SECONDS)
441-
{
438+
if cached.time.elapsed() > SANDBOX_CACHE_TIME_TO_LIVE {
442439
SandboxCacheOne::populate(&mut *cache, populator)
443440
} else {
444441
Ok(cached.value)

0 commit comments

Comments
 (0)