Impl Id convert methods
This commit is contained in:
1 parent
97e301b0d6
commit
ba834ac9b1
3 files changed
+22
-10
No files matched your search
+12
@@ -68,3 +68,15 @@ macro_rules! id_impl {
|
|||||||
|
|
||||||
id_impl!(u32, Id, INVALID_ID);
|
id_impl!(u32, Id, INVALID_ID);
|
||||||
id_impl!(u16, SmallId, INVALID_SMALL_ID);
|
id_impl!(u16, SmallId, INVALID_SMALL_ID);
|
||||||
|
|
||||||
|
impl From<SmallId> for Id {
|
||||||
|
fn from(value: SmallId) -> Self {
|
||||||
|
Self(value.0 as u32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Id> for SmallId {
|
||||||
|
fn from(value: Id) -> Self {
|
||||||
|
Self(value.0 as u16)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ use crate::data::entities::{CardState, EntityData};
|
|||||||
use crate::data::repositories::{BatchedDbLayer, DbLayer};
|
use crate::data::repositories::{BatchedDbLayer, DbLayer};
|
||||||
use crate::notification::MaybeError;
|
use crate::notification::MaybeError;
|
||||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||||
use log::info;
|
use log::debug;
|
||||||
use rusqlite::{Connection, Error, Params, Row};
|
use rusqlite::{Connection, Error, Params, Row};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
@@ -42,7 +42,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
|
|||||||
connection
|
connection
|
||||||
.execute(Q::load(), Q::update_params(entity))
|
.execute(Q::load(), Q::update_params(entity))
|
||||||
.map_err(|_| DbSaveError)?;
|
.map_err(|_| DbSaveError)?;
|
||||||
info!(
|
debug!(
|
||||||
"Updated in {} for {:?}",
|
"Updated in {} for {:?}",
|
||||||
Q::name(),
|
Q::name(),
|
||||||
time.elapsed()
|
time.elapsed()
|
||||||
@@ -58,7 +58,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
|
|||||||
.map_err(|_| DbSaveError)?;
|
.map_err(|_| DbSaveError)?;
|
||||||
|
|
||||||
entity.set_id(index.into());
|
entity.set_id(index.into());
|
||||||
info!(
|
debug!(
|
||||||
"Added into {} for {:?}",
|
"Added into {} for {:?}",
|
||||||
Q::name(),
|
Q::name(),
|
||||||
time.elapsed()
|
time.elapsed()
|
||||||
@@ -78,7 +78,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
|
|||||||
(&id,),
|
(&id,),
|
||||||
)
|
)
|
||||||
.map_err(|_| DbSaveError)?;
|
.map_err(|_| DbSaveError)?;
|
||||||
info!(
|
debug!(
|
||||||
"Deleted from {} for {:?}",
|
"Deleted from {} for {:?}",
|
||||||
Q::name(),
|
Q::name(),
|
||||||
time.elapsed()
|
time.elapsed()
|
||||||
@@ -98,7 +98,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> DbLayer<T> for SqliteDbLayer<T, Q
|
|||||||
|
|
||||||
iter.filter_map(|res| res.ok())
|
iter.filter_map(|res| res.ok())
|
||||||
.for_each(|i| storage.push(i));
|
.for_each(|i| storage.push(i));
|
||||||
info!(
|
debug!(
|
||||||
"Loaded {} from {} for {:?}",
|
"Loaded {} from {} for {:?}",
|
||||||
storage.len(),
|
storage.len(),
|
||||||
Q::name(),
|
Q::name(),
|
||||||
@@ -126,7 +126,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> BatchedDbLayer<T> for SqliteDbLay
|
|||||||
)
|
)
|
||||||
.map_err(|_| DbSaveError)?;
|
.map_err(|_| DbSaveError)?;
|
||||||
}
|
}
|
||||||
info!(
|
debug!(
|
||||||
"Deleted {} from {} for {:?}",
|
"Deleted {} from {} for {:?}",
|
||||||
ids.len(),
|
ids.len(),
|
||||||
Q::name(),
|
Q::name(),
|
||||||
@@ -160,7 +160,7 @@ impl<T: EntityData, Q: TableAccessQuerySet<T>> BatchedDbLayer<T> for SqliteDbLay
|
|||||||
entities[index].set_id(id.into());
|
entities[index].set_id(id.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(
|
debug!(
|
||||||
"Added {} into {} for {:?}",
|
"Added {} into {} for {:?}",
|
||||||
entities.len(),
|
entities.len(),
|
||||||
Q::name(),
|
Q::name(),
|
||||||
|
|||||||
+3
-3
@@ -37,7 +37,7 @@ use iced::keyboard::Event;
|
|||||||
use iced::widget::stack;
|
use iced::widget::stack;
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
use log::info;
|
use log::{debug, info};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -241,7 +241,7 @@ impl ScreenState {
|
|||||||
Import
|
Import
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
info!("Update took {:?}", time.elapsed());
|
debug!("Update took {:?}", time.elapsed());
|
||||||
|
|
||||||
task.0
|
task.0
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ impl ScreenState {
|
|||||||
|
|
||||||
let notifications = self.notification_manager.draw().map(Notification);
|
let notifications = self.notification_manager.draw().map(Notification);
|
||||||
|
|
||||||
info!("View took {:?}", time.elapsed());
|
debug!("View took {:?}", time.elapsed());
|
||||||
stack![view, notifications].width(Fill).height(Fill).into()
|
stack![view, notifications].width(Fill).height(Fill).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user