Browse Source

Add Display trait to all automatic Entity ID implementations.

Kestrel 1 year ago
parent
commit
bf1a35d6ca
3 changed files with 10 additions and 3 deletions
  1. 1 1
      microrm-macros/Cargo.toml
  2. 7 0
      microrm-macros/src/entity.rs
  3. 2 2
      microrm/Cargo.toml

+ 1 - 1
microrm-macros/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "microrm-macros"
-version = "0.2.4"
+version = "0.2.5"
 edition = "2021"
 license = "BSD-4-Clause"
 authors = ["Kestrel <kestrel@flying-kestrel.ca>"]

+ 7 - 0
microrm-macros/src/entity.rs

@@ -113,6 +113,7 @@ fn derive_id(
 ) -> proc_macro2::TokenStream {
     let struct_name = &input.ident;
     let id_name = format_ident!("{}ID", &input.ident);
+    let id_name_as_str = id_name.to_string();
 
     quote! {
         #[derive(Debug,PartialEq,Clone,Copy,#microrm_ref::re_export::serde::Serialize,#microrm_ref::re_export::serde::Deserialize)]
@@ -125,6 +126,12 @@ fn derive_id(
             fn raw_id(&self) -> i64 { self.0 }
         }
 
+        impl std::fmt::Display for #id_name {
+            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+                f.write_fmt(format_args!("{}({})", #id_name_as_str, self.0))
+            }
+        }
+
         impl #microrm_ref::model::Modelable for #id_name {
             fn bind_to(&self, stmt: &mut #microrm_ref::re_export::sqlite::Statement, col: usize) -> #microrm_ref::re_export::sqlite::Result<()> {
                 use #microrm_ref::re_export::sqlite::Bindable;

+ 2 - 2
microrm/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "microrm"
-version = "0.3.8"
+version = "0.3.9"
 edition = "2021"
 license = "BSD-4-Clause"
 authors = ["Kestrel <kestrel@flying-kestrel.ca>"]
@@ -18,7 +18,7 @@ serde_bytes = { version = "0.11.6" }
 serde_json = { version = "1.0" }
 lazy_static = { version = "1.4.0" }
 
-microrm-macros = { path = "../microrm-macros", version = "0.2.4" }
+microrm-macros = { path = "../microrm-macros", version = "0.2.5" }
 log = "0.4.17"
 
 [dev-dependencies]