-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-implement
#[derive(Identifiable)]
using Macros 1.1
This was extracted from #453. Going forward Macros 1.1 is the intended path of stabilization for procedural macros, so `diesel_codegen` will need to be rewritten to use it. Much of the helper code around this is a direct port of the libsyntax version of our code, rewritten to use `syn` instead.
- Loading branch information
Showing
7 changed files
with
140 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use quote::Tokens; | ||
use syn; | ||
|
||
use model::Model; | ||
|
||
pub fn derive_identifiable(item: syn::MacroInput) -> Tokens { | ||
let model = t!(Model::from_item(&item, "Identifiable")); | ||
let table_name = model.table_name(); | ||
let struct_ty = &model.ty; | ||
let fields = model.attrs; | ||
if !fields.iter().any(|f| f.field_name == Some(syn::Ident::new("id"))) { | ||
panic!("Could not find a field named `id` on `{}`", &model.name); | ||
} | ||
|
||
quote!(Identifiable! { | ||
( | ||
table_name = #table_name, | ||
struct_ty = #struct_ty, | ||
), | ||
fields = [#(fields)*], | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
diesel_compile_tests/tests/compile-fail/identifiable_requires_primary_key_field.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters