Merge factors type for authentication

This commit is contained in:
2022-11-11 12:26:02 +01:00
parent 8d231c0b45
commit af383720b7
44 changed files with 1177 additions and 674 deletions

View File

@@ -3,7 +3,10 @@ use std::slice::{Iter, IterMut};
use crate::utils::err::Res;
enum FileFormat { Json, Yaml }
enum FileFormat {
Json,
Yaml,
}
pub struct EntityManager<E> {
file_path: PathBuf,
@@ -11,8 +14,8 @@ pub struct EntityManager<E> {
}
impl<E> EntityManager<E>
where
E: serde::Serialize + serde::de::DeserializeOwned + Eq + Clone,
where
E: serde::Serialize + serde::de::DeserializeOwned + Eq + Clone,
{
/// Open entity
pub fn open_or_create<A: AsRef<Path>>(path: A) -> Res<Self> {
@@ -30,7 +33,7 @@ impl<E> EntityManager<E>
file_path: path.as_ref().to_path_buf(),
list: match Self::file_format(path.as_ref()) {
FileFormat::Json => serde_json::from_str(&file_content)?,
FileFormat::Yaml => serde_yaml::from_str(&file_content)?
FileFormat::Yaml => serde_yaml::from_str(&file_content)?,
},
})
}
@@ -49,7 +52,7 @@ impl<E> EntityManager<E>
fn file_format(p: &Path) -> FileFormat {
match p.to_string_lossy().ends_with(".json") {
true => FileFormat::Json,
false => FileFormat::Yaml
false => FileFormat::Yaml,
}
}
@@ -70,8 +73,8 @@ impl<E> EntityManager<E>
/// Replace entries in the list that matches a criteria
pub fn replace_entries<F>(&mut self, filter: F, el: &E) -> Res
where
F: Fn(&E) -> bool,
where
F: Fn(&E) -> bool,
{
for i in 0..self.list.len() {
if filter(&self.list[i]) {