Files
authy-oidc/src/utils.rs

40 lines
1.2 KiB
Rust

pub mod web {
/// Macro shenanigans to format a str at compile time
pub macro make_static_cache_header($max_age:expr, $stale_revalidate:expr) {{
// type guards lmfao
const _: ::std::time::Duration = $max_age;
const _: ::std::time::Duration = $stale_revalidate;
// hopefully ident encapsulation will save my ass here
const MAX_AGE: u64 = $max_age.as_secs();
const STALE_REVALIDATE: u64 = $stale_revalidate.as_secs();
const_str::format!(
"public, max-age={}, stale-while-revalidate={}",
MAX_AGE,
STALE_REVALIDATE
)
}}
#[cfg(test)]
mod test {
use std::time::Duration;
#[test]
fn const_concat_worked() {
const MA: Duration = Duration::from_mins(15);
const SR: Duration = Duration::from_hours(1);
const NAME: &str = super::make_static_cache_header!(MA, SR);
assert_eq!(
NAME,
format!(
"public, max-age={}, stale-while-revalidate={}",
MA.as_secs(),
SR.as_secs()
)
);
}
}
}