|
@@ -214,17 +214,40 @@ impl<T: 'static + serde::Serialize + serde::de::DeserializeOwned + std::fmt::Deb
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/// Helper trait to make working with [`Serialized`] fields a little bit nicer.
|
|
|
|
+pub trait Serializable: serde::Serialize + serde::de::DeserializeOwned + std::fmt::Debug + Clone {
|
|
|
|
+ /// Wrap an eligible object into a [`Serialized`] version of itself.
|
|
|
|
+ fn into_serialized(self) -> Serialized<Self> where Self: Sized;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl<T: 'static + serde::Serialize + serde::de::DeserializeOwned + std::fmt::Debug + Clone> Serializable for T {
|
|
|
|
+ fn into_serialized(self) -> Serialized<Self> where Self: Sized {
|
|
|
|
+ Serialized {
|
|
|
|
+ wrapped: self
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
// ----------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------
|
|
// Database specification types
|
|
// Database specification types
|
|
// ----------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
/// Table with EntityID-based lookup.
|
|
/// Table with EntityID-based lookup.
|
|
-#[derive(Clone)]
|
|
|
|
pub struct IDMap<T: Entity> {
|
|
pub struct IDMap<T: Entity> {
|
|
pub(crate) conn: Connection,
|
|
pub(crate) conn: Connection,
|
|
_ghost: std::marker::PhantomData<T>,
|
|
_ghost: std::marker::PhantomData<T>,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+impl<T: Entity> Clone for IDMap<T> {
|
|
|
|
+ fn clone(&self) -> Self {
|
|
|
|
+ Self {
|
|
|
|
+ conn: self.conn.clone(),
|
|
|
|
+ _ghost: Default::default(),
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
impl<T: Entity> IDMap<T> {
|
|
impl<T: Entity> IDMap<T> {
|
|
/// Construct a non-empty instance of an `IDMap`.
|
|
/// Construct a non-empty instance of an `IDMap`.
|
|
pub fn build(db: Connection) -> Self {
|
|
pub fn build(db: Connection) -> Self {
|