Skip to content

Commit 73161bf

Browse files
committed
Scope 'options' derive attributes under trait name.
1 parent 8459853 commit 73161bf

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

diesel/src/macros/macros_from_codegen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ macro_rules! infer_schema {
1515
($database_url: expr) => {
1616
mod __diesel_infer_schema {
1717
#[derive(InferSchema)]
18-
#[options(database_url=$database_url)]
18+
#[infer_schema_options(database_url=$database_url)]
1919
struct _Dummy;
2020
}
2121
pub use self::__diesel_infer_schema::*;
@@ -24,7 +24,7 @@ macro_rules! infer_schema {
2424
($database_url: expr, $schema_name: expr) => {
2525
mod __diesel_infer_schema {
2626
#[derive(InferSchema)]
27-
#[options(database_url=$database_url, schema_name=$schema_name)]
27+
#[infer_schema_options(database_url=$database_url, schema_name=$schema_name)]
2828
struct _Dummy;
2929
}
3030
pub use self::__diesel_infer_schema::*;
@@ -53,7 +53,7 @@ macro_rules! infer_schema {
5353
macro_rules! infer_table_from_schema {
5454
($database_url: expr, $table_name: expr) => {
5555
#[derive(InferTableFromSchema)]
56-
#[options(database_url=$database_url, table_name=$table_name)]
56+
#[infer_table_from_schema_options(database_url=$database_url, table_name=$table_name)]
5757
struct __DieselInferTableFromSchema;
5858
}
5959
}
@@ -83,7 +83,7 @@ macro_rules! embed_migrations {
8383
($migrations_path: expr) => {
8484
mod embedded_migrations {
8585
#[derive(EmbedMigrations)]
86-
#[options(migrations_path=$migrations_path)]
86+
#[embed_migrations_options(migrations_path=$migrations_path)]
8787
struct _Dummy;
8888
}
8989
}

diesel_codegen/src/embed_migrations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn derive_embed_migrations(input: syn::MacroInput) -> quote::Tokens {
1414
with your invocation of `embed_migrations!");
1515
}
1616

17-
let options = get_options_from_input(&input.attrs, bug);
17+
let options = get_options_from_input("embed_migrations_options", &input.attrs, bug);
1818
let migrations_path_opt = options.as_ref().map(|o| get_option(o, "migrations_path", bug));
1919
let migrations_expr = migration_directory_from_given_path(migrations_path_opt)
2020
.and_then(|path| migration_literals_from_path(&path));

diesel_codegen/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ pub fn derive_associations(input: TokenStream) -> TokenStream {
5757
expand_derive(input, associations::derive_associations)
5858
}
5959

60-
#[proc_macro_derive(InferSchema, attributes(options))]
60+
#[proc_macro_derive(InferSchema, attributes(infer_schema_options))]
6161
#[cfg(any(feature = "sqlite", feature = "postgres"))]
6262
pub fn derive_infer_schema(input: TokenStream) -> TokenStream {
6363
expand_derive(input, schema_inference::derive_infer_schema)
6464
}
6565

66-
#[proc_macro_derive(InferTableFromSchema, attributes(options))]
66+
#[proc_macro_derive(InferTableFromSchema, attributes(infer_table_from_schema_options))]
6767
#[cfg(any(feature = "sqlite", feature = "postgres"))]
6868
pub fn derive_infer_table_from_schema(input: TokenStream) -> TokenStream {
6969
expand_derive(input, schema_inference::derive_infer_table_from_schema)
7070
}
7171

72-
#[proc_macro_derive(EmbedMigrations, attributes(options))]
72+
#[proc_macro_derive(EmbedMigrations, attributes(embed_migrations_options))]
7373
pub fn derive_embed_migrations(input: TokenStream) -> TokenStream {
7474
expand_derive(input, embed_migrations::derive_embed_migrations)
7575
}

diesel_codegen/src/schema_inference.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pub fn derive_infer_schema(input: syn::MacroInput) -> quote::Tokens {
1111
with your invocation of `infer_schema!");
1212
}
1313

14-
let options = get_options_from_input(&input.attrs, bug).unwrap_or_else(|| bug());
14+
let options = get_options_from_input("infer_schema_options", &input.attrs, bug)
15+
.unwrap_or_else(|| bug());
1516
let database_url = get_option(&options, "database_url", bug);
1617
let schema_name = get_optional_option(&options, "schema_name");
1718

@@ -24,7 +25,8 @@ pub fn derive_infer_table_from_schema(input: syn::MacroInput) -> quote::Tokens {
2425
with your invocation of `infer_table_from_schema!");
2526
}
2627

27-
let options = get_options_from_input(&input.attrs, bug).unwrap_or_else(|| bug());
28+
let options = get_options_from_input("infer_table_from_schema_options", &input.attrs, bug)
29+
.unwrap_or_else(|| bug());
2830
let database_url = get_option(&options, "database_url", bug);
2931
let table_name = get_option(&options, "table_name", bug);
3032

diesel_codegen/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ pub fn inner_of_option_ty(ty: &Ty) -> Option<&Ty> {
109109
}
110110
}
111111

112-
pub fn get_options_from_input(attrs: &[Attribute], on_bug: fn() -> !)
112+
pub fn get_options_from_input(name: &str, attrs: &[Attribute], on_bug: fn() -> !)
113113
-> Option<Vec<MetaItem>>
114114
{
115-
let options = attrs.iter().find(|a| a.name() == "options").map(|a| &a.value);
115+
let options = attrs.iter().find(|a| a.name() == name).map(|a| &a.value);
116116
match options {
117117
Some(&MetaItem::List(_, ref options)) => {
118118
Some(options.iter().map(|o| match o {

0 commit comments

Comments
 (0)