Răsfoiți Sursa

Add rustfmt.toml.

Kestrel 7 luni în urmă
părinte
comite
d53c910e9f

+ 1 - 1
microrm-macros/src/database.rs

@@ -16,7 +16,7 @@ fn type_to_expression_context_type(ty: &syn::Type) -> proc_macro2::TokenStream {
             quote! {
                 #(#new_segments)::*
             }
-        }
+        },
         v => v.into_token_stream(),
     }
 }

+ 8 - 6
microrm-macros/src/entity.rs

@@ -13,7 +13,7 @@ fn extract_doc_comment(attrs: &[syn::Attribute]) -> proc_macro2::TokenStream {
                     }
                 }
                 None
-            }
+            },
             _ => None,
         })
         .next()
@@ -45,7 +45,9 @@ pub fn derive(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
             .into_iter()
             .map(|f| (f.ident.unwrap(), f.ty, f.attrs))
             .collect::<Vec<_>>(),
-        _ => panic!("Can only derive Entity on data structs with named fields!"),
+        _ => {
+            panic!("Can only derive Entity on data structs with named fields!")
+        },
     };
 
     let entity_ident = input.ident;
@@ -63,11 +65,11 @@ pub fn derive(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
         1 => {
             let ty = make_combined_name(plist.first().as_ref().unwrap());
             quote! { #ty }
-        }
+        },
         _ => {
             let tys = plist.iter().map(make_combined_name);
             quote! { ( #(#tys),* ) }
-        }
+        },
     };
 
     let vis = input.vis;
@@ -168,13 +170,13 @@ pub fn derive(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
                     quote! {
                         #ident: values
                     }
-                }
+                },
                 _ => {
                     let idx = syn::Index::from(i);
                     quote! {
                         #ident: values. #idx
                     }
-                }
+                },
             }
         })
         .collect::<Vec<_>>();

+ 4 - 4
microrm/src/cli.rs

@@ -277,19 +277,19 @@ mod tests {
             Ok(Params::Customer { cmd }) => {
                 cmd.perform(&(), c, &db.customers, &db.customers)
                     .expect("couldn't perform command");
-            }
+            },
             Ok(Params::Employee { cmd }) => {
                 cmd.perform(&(), c, &db.employees, &db.employees)
                     .expect("couldn't perform command");
-            }
+            },
             Ok(Params::Tx { cmd }) => {
                 cmd.perform(&(), &(), &db.transactions, &db.transactions)
                     .expect("couldn't perform command");
-            }
+            },
             Err(e) => {
                 println!("{}", e.render());
                 panic!("error parsing arguments")
-            }
+            },
         }
     }
 

+ 15 - 15
microrm/src/cli/clap_interface.rs

@@ -180,13 +180,13 @@ impl<O: CLIObject> InterfaceVerb<O> {
                     relation,
                     remote_keys,
                 }
-            }
+            },
             "create" => InterfaceVerb::Create(
                 <O::CreateParameters as clap::FromArgMatches>::from_arg_matches(matches)?,
             ),
             "delete" => {
                 InterfaceVerb::Delete(collect_keys::<O, IC>(matches, ValueRole::BaseTarget))
-            }
+            },
             "detach" => {
                 let (local_keys, relation, remote_keys) = Self::parse_attachment::<IC>(matches)?;
                 InterfaceVerb::Detach {
@@ -194,18 +194,18 @@ impl<O: CLIObject> InterfaceVerb<O> {
                     relation,
                     remote_keys,
                 }
-            }
+            },
             "list" => InterfaceVerb::ListAll,
             "inspect" => {
                 InterfaceVerb::Inspect(collect_keys::<O, IC>(matches, ValueRole::BaseTarget))
-            }
+            },
             cmd => {
                 if <O::ExtraCommands>::has_subcommand(cmd) {
                     InterfaceVerb::Extra(<O::ExtraCommands>::from_arg_matches(parent_matches)?)
                 } else {
                     unreachable!()
                 }
-            }
+            },
         })
     }
 }
@@ -235,7 +235,7 @@ impl<'l, Error: CLIError, OE: Entity> Attacher<'l, Error, OE> {
                 } else {
                     self.err = map.disconnect_from(obj.id()).err().map(Into::into);
                 }
-            }
+            },
             Ok(None) => {
                 self.err = Some(Error::no_such_entity(
                     E::entity_name(),
@@ -246,10 +246,10 @@ impl<'l, Error: CLIError, OE: Entity> Attacher<'l, Error, OE> {
                         .unwrap()
                         .to_string(),
                 ));
-            }
+            },
             Err(e) => {
                 self.err = Some(e.into());
-            }
+            },
         }
     }
 }
@@ -371,10 +371,10 @@ impl<O: CLIObject, IC: InterfaceCustomization> ClapInterface<O, IC> {
                 if let Some(err) = attacher.err {
                     return Err(err);
                 }
-            }
+            },
             InterfaceVerb::Create(params) => {
                 insert_ctx.insert(O::create_from_params(data, params)?)?;
-            }
+            },
             InterfaceVerb::Delete(keys) => {
                 let keys = EntityKey::to_string_vec(keys, ic);
                 query_ctx
@@ -382,7 +382,7 @@ impl<O: CLIObject, IC: InterfaceCustomization> ClapInterface<O, IC> {
                         UniqueList::<O>::build_equivalent(keys.iter().map(String::as_str)).unwrap(),
                     )
                     .delete()?;
-            }
+            },
             InterfaceVerb::Detach {
                 local_keys,
                 relation,
@@ -418,7 +418,7 @@ impl<O: CLIObject, IC: InterfaceCustomization> ClapInterface<O, IC> {
                 if let Some(err) = attacher.err {
                     return Err(err);
                 }
-            }
+            },
             InterfaceVerb::ListAll => {
                 println!(
                     "Listing all {}(s): ({})",
@@ -428,7 +428,7 @@ impl<O: CLIObject, IC: InterfaceCustomization> ClapInterface<O, IC> {
                 for obj in query_ctx.get()?.into_iter() {
                     println!(" - {}", obj.shortname());
                 }
-            }
+            },
             InterfaceVerb::Inspect(keys) => {
                 let keys = EntityKey::to_string_vec(keys, ic);
                 let obj = query_ctx
@@ -491,10 +491,10 @@ impl<O: CLIObject, IC: InterfaceCustomization> ClapInterface<O, IC> {
                 }
 
                 obj.accept_part_visitor_ref(&mut RelationFieldWalker(Default::default()));
-            }
+            },
             InterfaceVerb::Extra(extra) => {
                 O::run_extra_command(data, extra, query_ctx, insert_ctx)?;
-            }
+            },
         }
         Ok(())
     }

+ 6 - 6
microrm/src/db.rs

@@ -178,7 +178,7 @@ impl Connection {
                 let stmt = e.insert(Statement { sqlite: conn, stmt });
 
                 run_query(stmt.make_context()?)
-            }
+            },
             Entry::Occupied(mut e) => run_query(e.get_mut().make_context()?),
         }
     }
@@ -340,11 +340,11 @@ impl<'a> StatementContext<'a> {
             sq::SQLITE_DONE => {
                 self.done.set(true);
                 Ok(false)
-            }
+            },
             sq::SQLITE_BUSY => {
                 log::trace!("Concurrent database access!");
                 todo!()
-            }
+            },
             sq::SQLITE_CONSTRAINT => {
                 let msg = unsafe { CStr::from_ptr(sq::sqlite3_errmsg(self.stmt.sqlite)) }
                     .to_str()
@@ -352,12 +352,12 @@ impl<'a> StatementContext<'a> {
                     .to_string();
                 log::trace!("SQLite constraint violation: {msg}");
                 Err(Error::ConstraintViolation(msg))
-            }
+            },
             err => {
                 log::trace!("unexpected error during sqlite3_step: {:?}", err);
                 check_rcode(|| None, err)?;
                 unreachable!()
-            }
+            },
         }
     }
 
@@ -606,7 +606,7 @@ impl Readable for Vec<u8> {
                 )),
                 std::cmp::Ordering::Greater => {
                     Ok(std::slice::from_raw_parts(ptr.cast(), len as usize).to_vec())
-                }
+                },
             }
         }
     }

+ 10 - 9
microrm/src/query.rs

@@ -96,14 +96,14 @@ impl<'l> Query<'l> {
             None => String::new(),
             Some(v) => {
                 format!("FROM {}", v.into_iter().join(","))
-            }
+            },
         };
 
         let set_ = match self.parts.remove(&QueryPart::Set) {
             None => String::new(),
             Some(v) => {
                 format!("SET {}", v.into_iter().join(","))
-            }
+            },
         };
 
         let join_ = match self.parts.remove(&QueryPart::Join) {
@@ -119,7 +119,7 @@ impl<'l> Query<'l> {
             None => String::new(),
             Some(v) => {
                 format!("WHERE {}", v.into_iter().join(" AND "))
-            }
+            },
         };
 
         let trailing_ = match self.parts.remove(&QueryPart::Trailing) {
@@ -409,10 +409,7 @@ pub trait Queryable: Clone {
                 self.build()
                     .replace(
                         QueryPart::Columns,
-                        format!(
-                            "`{}`.`id`",
-                            Self::EntityOutput::entity_name()
-                        ),
+                        format!("`{}`.`id`", Self::EntityOutput::entity_name()),
                     )
                     .assemble()
             },
@@ -421,7 +418,9 @@ pub trait Queryable: Clone {
                 let mut index = 1;
                 self.bind(&mut ctx, &mut index);
 
-                <<Self::OutputContainer as OutputContainer<Self::EntityOutput>>::IDContainer>::assemble_from(ctx)
+                <<Self::OutputContainer as OutputContainer<
+                        Self::EntityOutput,
+                    >>::IDContainer>::assemble_from(ctx)
             },
         )?;
         txn.commit()?;
@@ -544,7 +543,9 @@ pub trait Queryable: Clone {
         part: EP,
     ) -> impl Queryable<
         EntityOutput = <EP::Datum as EntityID>::Entity,
-        OutputContainer = <Self::OutputContainer as OutputContainer<Self::EntityOutput>>::ReplacedEntity<<EP::Datum as EntityID>::Entity>,
+        OutputContainer = <Self::OutputContainer as OutputContainer<
+            Self::EntityOutput,
+        >>::ReplacedEntity<<EP::Datum as EntityID>::Entity>,
     >
     where
         Self: Sized,

+ 2 - 2
microrm/src/query/components.rs

@@ -380,13 +380,13 @@ impl<
                     "{remote_name}_{local_name}_relation_{}",
                     d.1.unwrap_or(EP::part_name())
                 )
-            }
+            },
             LocalSide::Domain => {
                 format!(
                     "{local_name}_{remote_name}_relation_{}",
                     d.1.unwrap_or(EP::part_name())
                 )
-            }
+            },
         };
 
         self.parent

+ 2 - 2
microrm/src/schema.rs

@@ -298,13 +298,13 @@ pub trait Database {
         let schema = build::collect_from_database::<Self>();
         match schema.check(conn.clone()) {
             // schema checks out
-            Some(true) => {}
+            Some(true) => {},
             // schema doesn't match
             Some(false) => Err(Error::IncompatibleSchema)?,
             // no schema found
             None => {
                 schema.create(conn.clone())?;
-            }
+            },
         }
 
         conn.execute_raw_sql("PRAGMA foreign_keys = ON")?;

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

@@ -230,7 +230,7 @@ pub(crate) fn collect_from_database<DB: Database>() -> DatabaseSchema {
                         .push("unique(`range`, `domain`)".to_string());
 
                     tables.insert(relation_table_name.clone(), relation_table);
-                }
+                },
                 PartType::RelationRange {
                     table_name: relation_table_name,
                     domain_name,
@@ -256,7 +256,7 @@ pub(crate) fn collect_from_database<DB: Database>() -> DatabaseSchema {
                         .constraints
                         .push("unique(`range`, `domain`)".to_string());
                     tables.insert(relation_table_name.clone(), relation_table);
-                }
+                },
             }
         }
 

+ 3 - 3
microrm/tests/injective.rs

@@ -86,12 +86,12 @@ fn single_connection() {
     match a1.works.connect_to(b2_id) {
         Err(microrm::Error::ConstraintViolation(_)) => {
             // all good
-        }
+        },
         Err(_) => {
             panic!("Unexpected error while testing injective connection");
-        }
+        },
         Ok(_) => {
             panic!("Unexpected success while testing injective connection");
-        }
+        },
     }
 }

+ 3 - 0
rustfmt.toml

@@ -0,0 +1,3 @@
+match_block_trailing_comma = true
+use_field_init_shorthand = true
+max_width = 100