Skip to content

Commit c17b656

Browse files
committed
Module reorganisation
1 parent 203e43d commit c17b656

8 files changed

Lines changed: 24 additions & 17 deletions

File tree

lib/src/anon.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// You may obtain a copy of the License in the LICENSE-APACHE file or at:
44
// https://www.apache.org/licenses/LICENSE-2.0
55

6+
//! The `impl_anon!` macro
7+
68
use crate::fields::{Field, Fields, FieldsNamed, FieldsUnnamed, StructStyle};
7-
use crate::{IdentFormatter, Scope, ScopeItem};
9+
use crate::scope::{Scope, ScopeItem};
10+
use crate::IdentFormatter;
811
use proc_macro2::{Span, TokenStream};
912
use quote::{quote, ToTokens, TokenStreamExt};
1013
use syn::token::{Brace, Colon, Comma, Eq, Paren, Semi};

lib/src/autoimpl.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! Implementation of the `#[autoimpl]` attribute
77
88
use crate::generics::{clause_to_toks, WhereClause};
9-
use crate::{ForDeref, SimplePath};
9+
use crate::SimplePath;
1010
use proc_macro2::{Span, TokenStream as Toks};
1111
use proc_macro_error::emit_error;
1212
use quote::{quote, TokenStreamExt};
@@ -17,9 +17,11 @@ use syn::{
1717
Token,
1818
};
1919

20+
mod for_deref;
2021
mod impl_misc;
2122
mod impl_using;
2223

24+
pub use for_deref::ForDeref;
2325
pub use impl_misc::*;
2426
pub use impl_using::*;
2527

lib/src/default.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
use crate::fields::{Fields, FieldsNamed, FieldsUnnamed};
77
use crate::generics::{clause_to_toks, WhereClause};
8-
use crate::{Scope, ScopeAttr, ScopeItem, SimplePath};
8+
use crate::scope::{Scope, ScopeAttr, ScopeItem};
9+
use crate::SimplePath;
910
use proc_macro2::{Span, TokenStream};
1011
use proc_macro_error::emit_error;
1112
use quote::quote;
@@ -189,7 +190,7 @@ impl Parse for ImplDefault {
189190
/// Helper fn which can be passed to [`Scope::apply_attrs`]
190191
///
191192
/// This optionally matches [`AttrImplDefault`].
192-
pub fn find_attr_impl_default(path: &syn::Path) -> Option<&'static dyn ScopeAttr> {
193+
pub fn find_impl_default(path: &syn::Path) -> Option<&'static dyn ScopeAttr> {
193194
AttrImplDefault
194195
.path()
195196
.matches(path)

lib/src/fields.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ pub struct Field {
7676
/// Optional field initializer.
7777
///
7878
/// This is considered legal input when parsing, but not legal output. An
79-
/// attribute rule such as [`crate::AttrImplDefault`] must remove the
80-
/// initializer before output is generated.
79+
/// attribute rule such as [`AttrImplDefault`](crate::scope::AttrImplDefault)
80+
/// must remove the initializer before output is generated.
8181
pub assign: Option<(Token![=], Expr)>,
8282
}
8383

lib/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,15 @@
1414
#![allow(clippy::unnecessary_lazy_evaluations)]
1515
#![allow(clippy::style)]
1616

17-
mod anon;
17+
pub mod anon;
1818
pub mod autoimpl;
1919
mod default;
2020
pub mod fields;
21-
mod for_deref;
2221
pub mod generics;
23-
mod scope;
22+
pub mod scope;
2423

25-
pub use anon::{Anon, AnonField, AnonScope};
26-
pub use default::{find_attr_impl_default, AttrImplDefault, ImplDefault};
27-
pub use for_deref::ForDeref;
24+
pub use default::ImplDefault;
2825
use proc_macro2::Span;
29-
pub use scope::{Scope, ScopeAttr, ScopeItem};
3026
use syn::Ident;
3127

3228
/// Tool to make a formatted [`Ident`](struct@Ident)

lib/src/scope.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// You may obtain a copy of the License in the LICENSE-APACHE file or at:
44
// https://www.apache.org/licenses/LICENSE-2.0
55

6+
//! The `impl_scope!` macro
7+
68
use crate::{fields::Fields, SimplePath};
79
use proc_macro2::{Span, TokenStream};
810
use proc_macro_error::emit_error;
@@ -15,6 +17,8 @@ use syn::{
1517
Token, Type, Variant, Visibility,
1618
};
1719

20+
pub use super::default::{find_impl_default, AttrImplDefault};
21+
1822
/// Attribute rule for [`Scope`]
1923
///
2024
/// Rules are matched via a path, e.g. `&["foo"]` matches `foo` and

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ doc_comment::doctest!("../README.md");
3939

4040
extern crate proc_macro;
4141

42+
use lib::{anon, scope};
4243
use proc_macro::TokenStream;
4344
use proc_macro_error::{emit_call_site_error, proc_macro_error};
4445
use syn::parse_macro_input;
@@ -372,8 +373,8 @@ pub fn autoimpl(attr: TokenStream, item: TokenStream) -> TokenStream {
372373
#[proc_macro_error]
373374
#[proc_macro]
374375
pub fn impl_scope(input: TokenStream) -> TokenStream {
375-
let mut scope = parse_macro_input!(input as lib::Scope);
376-
scope.apply_attrs(lib::find_attr_impl_default);
376+
let mut scope = parse_macro_input!(input as scope::Scope);
377+
scope.apply_attrs(scope::find_impl_default);
377378
scope.expand().into()
378379
}
379380

@@ -421,7 +422,7 @@ pub fn impl_scope(input: TokenStream) -> TokenStream {
421422
#[proc_macro_error]
422423
#[proc_macro]
423424
pub fn impl_anon(input: TokenStream) -> TokenStream {
424-
let mut scope = parse_macro_input!(input as lib::Anon).into_scope();
425-
scope.apply_attrs(lib::find_attr_impl_default);
425+
let mut scope = parse_macro_input!(input as anon::Anon).into_scope();
426+
scope.apply_attrs(scope::find_impl_default);
426427
scope.expand().into()
427428
}

0 commit comments

Comments
 (0)