Reformat code

This commit is contained in:
micialware committed 2026-08-31 11:26:05 +03:00
1 parent 2fc58fcc2d
commit 29a90d48d9
8 files changed
+23 -30

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@ pub mod repositories;
use rusqlite::ToSql;
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
use std::fmt::{write, Display, Formatter};
use std::fmt::{Display, Formatter, write};
use std::num::ParseIntError;
use std::str::FromStr;
@@ -63,7 +63,7 @@ macro_rules! id_impl {
self.0 != 0
}
}
}
};
}
id_impl!(u32, Id, INVALID_ID);
+1 -1
View File
@@ -3,13 +3,13 @@ use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, OrderMode, WordOpenMode};
use crate::data::{INVALID_ID, Id};
use chrono::{DateTime, NaiveDate, Utc};
use fsrs::MemoryState;
use litemap::LiteMap;
use log::info;
use rayon::prelude::*;
use rhai::{Engine, Scope};
use std::cmp::Ordering;
use std::marker::PhantomData;
use std::time::Instant;
use litemap::LiteMap;
#[derive(Clone, Debug)]
pub struct WordData {
+3 -2
View File
@@ -320,7 +320,8 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
}
fn create_now(&mut self, mut new: T) -> Result<EntityHandle<T>, NotificationData> {
self.data_layer.add_entity(&mut new, &self.connection.read())?;
self.data_layer
.add_entity(&mut new, &self.connection.read())?;
let index = self.cache.len();
let handle = EntityHandle::new(new.id(), index, true);
self.cache.push(new);
@@ -378,7 +379,7 @@ impl<T: EntityData + Clone, D: DbLayer<T>> Repository<T, D> for DataRepositoryIn
fn start(&mut self) -> MaybeError {
if self.version != 0 {
return Ok(())
return Ok(());
}
self.init()?;
+1 -1
View File
@@ -1,6 +1,6 @@
use rusqlite::{Error, Params, Row};
use crate::data::entities::WordGroup;
use crate::data_provider::TableAccessQuerySet;
use rusqlite::{Error, Params, Row};
pub struct CustomFieldsQuerySet;
impl TableAccessQuerySet<WordGroup> for CustomFieldsQuerySet {
+7 -1
View File
@@ -46,7 +46,13 @@ impl TableAccessQuerySet<DeckSettings> for DeckQuerySet {
}
fn update_params(entity: &DeckSettings) -> impl Params {
(&entity.name, &entity.forward, &entity.backward, &entity.filter, entity.id)
(
&entity.name,
&entity.forward,
&entity.backward,
&entity.filter,
entity.id,
)
}
}
+5 -17
View File
@@ -9,6 +9,7 @@ use std::marker::PhantomData;
use std::time::Instant;
pub(crate) mod card_states;
pub mod custom_fields;
pub(crate) mod decks;
pub(crate) mod history;
pub(crate) mod import;
@@ -16,9 +17,8 @@ pub(crate) mod settings;
pub(crate) mod sqlite;
pub(crate) mod voice;
pub(crate) mod web_api;
pub(crate) mod words;
pub mod word_groups;
pub mod custom_fields;
pub(crate) mod words;
pub trait TableAccessQuerySet<T> {
fn load() -> &'static str;
@@ -44,11 +44,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
connection
.execute(Q::load(), Q::update_params(entity))
.map_err(|_| DbSaveError)?;
debug!(
"Updated in {} for {:?}",
Q::name(),
time.elapsed()
);
debug!("Updated in {} for {:?}", Q::name(), time.elapsed());
Ok(())
}
@@ -60,11 +56,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
.map_err(|_| DbSaveError)?;
entity.set_id(index.into());
debug!(
"Added into {} for {:?}",
Q::name(),
time.elapsed()
);
debug!("Added into {} for {:?}", Q::name(), time.elapsed());
Ok(())
}
@@ -80,11 +72,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
(&id,),
)
.map_err(|_| DbSaveError)?;
debug!(
"Deleted from {} for {:?}",
Q::name(),
time.elapsed()
);
debug!("Deleted from {} for {:?}", Q::name(), time.elapsed());
Ok(())
}
+1 -1
View File
@@ -1,6 +1,6 @@
use rusqlite::{Error, Params, Row};
use crate::data::entities::WordGroup;
use crate::data_provider::TableAccessQuerySet;
use rusqlite::{Error, Params, Row};
pub struct WordGroupQuerySet;
impl TableAccessQuerySet<WordGroup> for WordGroupQuerySet {
+3 -5
View File
@@ -2,9 +2,9 @@ use crate::data::entities::{WordData, WordGroup};
use crate::data_provider::TableAccessQuerySet;
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
use crate::notification::{MaybeError, NotificationData};
use litemap::LiteMap;
use rusqlite::{Connection, Error, Params, Row, params};
use std::collections::HashMap;
use litemap::LiteMap;
pub struct WordQuerySet;
impl TableAccessQuerySet<WordData> for WordQuerySet {
@@ -31,8 +31,7 @@ impl TableAccessQuerySet<WordData> for WordQuerySet {
key: row.get(1)?,
value: row.get(2)?,
tags: row.get(3)?,
additional: serde_json::from_str(&additional)
.unwrap_or_default(),
additional: serde_json::from_str(&additional).unwrap_or_default(),
group_id: row.get(5)?,
})
}
@@ -153,8 +152,7 @@ pub fn load_words(connection: &Connection) -> Result<Vec<WordData>, Notification
key: row.get(1)?,
value: row.get(2)?,
tags: row.get(3)?,
additional: serde_json::from_str(&additional)
.unwrap_or_default(),
additional: serde_json::from_str(&additional).unwrap_or_default(),
group_id: row.get(5)?,
})
})