Format code

This commit is contained in:
2022-04-03 15:50:49 +02:00
parent 9236b91f12
commit b965fa6b4f
20 changed files with 149 additions and 106 deletions

View File

@@ -8,7 +8,10 @@ pub struct EntityManager<E> {
list: Vec<E>,
}
impl<E> EntityManager<E> where E: serde::Serialize + serde::de::DeserializeOwned + Eq + Clone {
impl<E> EntityManager<E>
where
E: serde::Serialize + serde::de::DeserializeOwned + Eq + Clone,
{
/// Open entity
pub fn open_or_create<A: AsRef<Path>>(path: A) -> Res<Self> {
if !path.as_ref().is_file() {
@@ -37,7 +40,10 @@ impl<E> EntityManager<E> where E: serde::Serialize + serde::de::DeserializeOwned
/// Save the list
fn save(&self) -> Res {
Ok(std::fs::write(&self.file_path, serde_json::to_string(&self.list)?)?)
Ok(std::fs::write(
&self.file_path,
serde_json::to_string(&self.list)?,
)?)
}
/// Insert a new element in the list
@@ -47,7 +53,10 @@ impl<E> EntityManager<E> where E: serde::Serialize + serde::de::DeserializeOwned
}
/// 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 {
pub fn replace_entries<F>(&mut self, filter: F, el: &E) -> Res
where
F: Fn(&E) -> bool,
{
for i in 0..self.list.len() {
if filter(&self.list[i]) {
self.list[i] = el.clone();
@@ -61,4 +70,4 @@ impl<E> EntityManager<E> where E: serde::Serialize + serde::de::DeserializeOwned
pub fn iter(&self) -> Iter<'_, E> {
self.list.iter()
}
}
}