Skip to content

Commit

Permalink
chore: vec to hashset (#15)
Browse files Browse the repository at this point in the history
* chore: vec to hashset

* chore: cargo fmt

---------

Co-authored-by: Luciano Mammino <lucianomammino@gmail.com>
  • Loading branch information
ilteoood and lmammino committed Apr 27, 2024
1 parent efbac0c commit 4670d45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/accepted_algorithms.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use jsonwebtoken::Algorithm;
use std::str::FromStr;
use std::{collections::HashSet, str::FromStr};
use thiserror::Error;

#[derive(Debug, Clone, Default)]
pub struct AcceptedAlgorithms(Vec<Algorithm>);
pub struct AcceptedAlgorithms(HashSet<Algorithm>);

#[derive(Debug, Error)]
pub enum AcceptedAlgorithmsError {
Expand Down Expand Up @@ -57,7 +57,7 @@ impl FromStr for AcceptedAlgorithms {
}
}

Ok(Self(algorithms))
Ok(Self(algorithms.into_iter().collect()))
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/accepted_claims.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde_json::Value;
use std::fmt::Display;
use std::{collections::HashSet, fmt::Display};

#[derive(Debug, Clone, Default, Eq, PartialEq)]
pub struct AcceptedClaims(Vec<String>, String);
pub struct AcceptedClaims(HashSet<String>, String);

pub enum StringOrArray<'a> {
String(&'a str),
Expand Down Expand Up @@ -31,7 +31,7 @@ impl<S: Display> From<&[S]> for StringOrArray<'_> {
}

impl AcceptedClaims {
pub fn new(accepted_values: Vec<String>, claim_name: String) -> Self {
pub fn new(accepted_values: HashSet<String>, claim_name: String) -> Self {
Self(accepted_values, claim_name)
}

Expand All @@ -42,7 +42,7 @@ impl AcceptedClaims {
.filter(|s| !s.is_empty())
.collect::<Vec<_>>();

Self::new(accepted_values, claim_name)
Self::new(accepted_values.into_iter().collect(), claim_name)
}

pub fn is_accepted(&self, claim_value: &StringOrArray) -> bool {
Expand Down Expand Up @@ -116,7 +116,9 @@ mod tests {
vec![
"https://example.com".to_string(),
"https://example.org".to_string()
],
]
.into_iter()
.collect(),
"iss".to_string()
)
);
Expand Down

0 comments on commit 4670d45

Please sign in to comment.