From 006855638291aeb434aec9fdfdafccbc6a853bcc Mon Sep 17 00:00:00 2001 From: asonix Date: Mon, 28 Nov 2022 18:25:00 -0600 Subject: [PATCH] Constify Config --- src/lib.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5fb5741..e6e362a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,7 @@ const SIGNATURE_FIELD: &str = "signature"; pub struct Config { expires_after: Duration, use_created_field: bool, - required_headers: HashSet, + required_headers: Vec, } #[derive(Debug)] @@ -155,8 +155,12 @@ impl RequiredError { impl Config { /// Create a new Config with a default expiration of 10 seconds - pub fn new() -> Self { - Config::default() + pub const fn new() -> Self { + Config { + expires_after: Duration::from_secs(10), + use_created_field: true, + required_headers: Vec::new(), + } } /// Enable mastodon compatibility @@ -184,14 +188,14 @@ impl Config { } /// Set the expiration to a custom duration - pub fn set_expiration(mut self, expires_after: Duration) -> Self { + pub const fn set_expiration(mut self, expires_after: Duration) -> Self { self.expires_after = expires_after; self } /// Mark a header as required pub fn require_header(mut self, header: &str) -> Self { - self.required_headers.insert(header.to_lowercase()); + self.required_headers.push(header.to_lowercase()); self } @@ -226,7 +230,7 @@ impl Config { expires, &sig_headers, &mut headers, - self.required_headers.clone(), + self.required_headers.iter().cloned().collect(), )?; Ok(Unsigned { @@ -260,7 +264,7 @@ impl Config { method, path_and_query, &mut headers, - self.required_headers.clone(), + self.required_headers.iter().cloned().collect(), )?; Ok(unvalidated.validate(self.expires_after)?) @@ -325,11 +329,7 @@ fn build_signing_string( impl Default for Config { fn default() -> Self { - Config { - expires_after: Duration::from_secs(10), - use_created_field: true, - required_headers: HashSet::new(), - } + Self::new() } }