Bläddra i källkod

rustfmt pass.

Kestrel 1 år sedan
förälder
incheckning
4cc45a2dd4

+ 15 - 9
microrm/src/schema.rs

@@ -1,8 +1,8 @@
 use crate::{
-    schema::datum::Datum,
     db::{Connection, DBConnection},
-    schema::entity::{Entity, EntityPartList, EntityVisitor},
     query,
+    schema::datum::Datum,
+    schema::entity::{Entity, EntityPartList, EntityVisitor},
 };
 use crate::{DBError, DBResult};
 
@@ -15,7 +15,6 @@ pub(crate) mod meta;
 #[cfg(test)]
 mod tests;
 
-
 // ----------------------------------------------------------------------
 // API types
 // ----------------------------------------------------------------------
@@ -65,7 +64,6 @@ impl<T: Entity> std::ops::DerefMut for IDWrap<T> {
     }
 }
 
-
 // ----------------------------------------------------------------------
 // Entity field types
 // ----------------------------------------------------------------------
@@ -100,7 +98,7 @@ pub trait Relation: 'static {
 /// XXX: we want to be able to derive a string name from a Relation instance, preferably without
 /// another proc macro, and without relying on RTTI that could change between compilations. how?
 ///
-/// -> can use a regular macro to automatically declare tag struct and impl Relation 
+/// -> can use a regular macro to automatically declare tag struct and impl Relation
 
 /// Opaque data structure used for constructing `Assoc{Map,Domain,Range}` instances.
 pub struct AssocData {
@@ -163,7 +161,10 @@ impl<T: Entity> Datum for AssocMap<T> {
         v.visit::<T>();
     }
 
-    fn accept_discriminator(d: &mut impl DatumDiscriminator) where Self: Sized {
+    fn accept_discriminator(d: &mut impl DatumDiscriminator)
+    where
+        Self: Sized,
+    {
         d.visit_assoc_map::<T>();
     }
 
@@ -227,7 +228,10 @@ impl<R: Relation> Datum for AssocDomain<R> {
         v.visit::<R::Domain>();
     }
 
-    fn accept_discriminator(d: &mut impl DatumDiscriminator) where Self: Sized {
+    fn accept_discriminator(d: &mut impl DatumDiscriminator)
+    where
+        Self: Sized,
+    {
         d.visit_assoc_domain::<R>();
     }
 
@@ -274,7 +278,6 @@ impl<R: Relation> AssocRange<R> {
     }
 }
 
-
 impl<R: Relation> EntityMap for AssocRange<R> {
     type ContainedEntity = R::Domain;
 
@@ -292,7 +295,10 @@ impl<R: Relation> Datum for AssocRange<R> {
         v.visit::<R::Domain>();
     }
 
-    fn accept_discriminator(d: &mut impl DatumDiscriminator) where Self: Sized {
+    fn accept_discriminator(d: &mut impl DatumDiscriminator)
+    where
+        Self: Sized,
+    {
         d.visit_assoc_range::<R>();
     }
 

+ 2 - 4
microrm/src/schema/build.rs

@@ -139,10 +139,8 @@ pub(crate) fn collect_from_database<DB: Database>() -> DatabaseSchema {
                     })
                 }
                 PartType::Assoc(assoc_name) => {
-                    let assoc_table_name = format!(
-                        "{}_assoc_{}_{}",
-                        state.name, part.name, assoc_name
-                    );
+                    let assoc_table_name =
+                        format!("{}_assoc_{}_{}", state.name, part.name, assoc_name);
                     let mut assoc_table = TableInfo::new(assoc_table_name.clone());
                     assoc_table.dependencies.push(table_name.clone());
                     assoc_table.dependencies.push(format!("{}", assoc_name));

+ 3 - 12
microrm/src/schema/collect.rs

@@ -77,9 +77,7 @@ impl EntityStateContainer {
     }
 
     pub fn make_context(&mut self) -> EntityContext {
-        EntityContext {
-            container: self,
-        }
+        EntityContext { container: self }
     }
 }
 
@@ -93,18 +91,11 @@ impl<'a> EntityVisitor for EntityContext<'a> {
         // 1. we haven't seen this entity
         // 2. we've seen this entity before
 
-        if self
-            .container
-            .states
-            .contains_key(E::entity_name())
-        {
+        if self.container.states.contains_key(E::entity_name()) {
             return;
         }
 
-        let entry = self
-            .container
-            .states
-            .entry(E::entity_name());
+        let entry = self.container.states.entry(E::entity_name());
 
         let entry = entry.or_insert_with(EntityState::build::<E>);
         // sanity-check

+ 8 - 2
microrm/src/schema/datum.rs

@@ -1,4 +1,7 @@
-use crate::{schema::{AssocData, DatumDiscriminator, EntityVisitor}, DBResult};
+use crate::{
+    schema::{AssocData, DatumDiscriminator, EntityVisitor},
+    DBResult,
+};
 
 // trait implementations for Datum
 mod datum_common;
@@ -23,7 +26,10 @@ pub trait Datum: 'static {
         Self: Sized;
 
     fn accept_entity_visitor(_: &mut impl EntityVisitor) {}
-    fn accept_discriminator(d: &mut impl DatumDiscriminator) where Self: Sized {
+    fn accept_discriminator(d: &mut impl DatumDiscriminator)
+    where
+        Self: Sized,
+    {
         d.visit_bare_field::<Self>();
     }
 }

+ 4 - 1
microrm/src/schema/datum/datum_common.rs

@@ -1,4 +1,7 @@
-use crate::{schema::{AssocData,Datum}, DBResult};
+use crate::{
+    schema::{AssocData, Datum},
+    DBResult,
+};
 
 impl Datum for String {
     fn sql_type() -> &'static str {

+ 1 - 1
microrm/src/schema/entity.rs

@@ -1,8 +1,8 @@
 use std::{fmt::Debug, hash::Hash};
 
 use crate::{
-    schema::datum::{Datum, DatumList},
     db::DBConnection,
+    schema::datum::{Datum, DatumList},
     DBResult,
 };
 

+ 15 - 9
microrm/src/schema/tests.rs

@@ -237,7 +237,7 @@ mod derive_tests {
 
 mod mutual_relationship {
     use super::open_test_db;
-    use crate::schema::{AssocMap, Database, IDMap, AssocRange, AssocDomain};
+    use crate::schema::{AssocDomain, AssocMap, AssocRange, Database, IDMap};
     use microrm_macros::{Database, Entity};
 
     struct CR;
@@ -271,14 +271,20 @@ mod mutual_relationship {
         let db = open_test_db::<ReceiptDB>("mutual_relationship_create");
         // let db = ReceiptDB::open_path(":memory:").expect("couldn't open in-memory database");
 
-        let ca = db.customers.insert(Customer {
-            name: "customer A".to_string(),
-            receipts: Default::default(),
-        }).expect("couldn't insert customer record");
+        let ca = db
+            .customers
+            .insert(Customer {
+                name: "customer A".to_string(),
+                receipts: Default::default(),
+            })
+            .expect("couldn't insert customer record");
 
-        let ra = db.receipts.insert(Receipt {
-            value: 32usize,
-            customers: Default::default(),
-        }).expect("couldn't insert receipt record");
+        let ra = db
+            .receipts
+            .insert(Receipt {
+                value: 32usize,
+                customers: Default::default(),
+            })
+            .expect("couldn't insert receipt record");
     }
 }