1
1
use std:: ops:: Deref ;
2
2
3
3
use proc_macro2:: TokenStream ;
4
- use syn:: { Attribute , Ident } ;
4
+ use syn:: { Attribute , Ident , Visibility } ;
5
5
6
6
use crate :: { attrs:: common:: ContainerAttributes , codegen:: common:: ContainerVersion } ;
7
7
21
21
Self : Sized + Deref < Target = VersionedContainer < I > > ,
22
22
{
23
23
/// Creates a new versioned container.
24
- fn new (
25
- ident : Ident ,
26
- data : D ,
27
- attributes : ContainerAttributes ,
28
- original_attributes : Vec < Attribute > ,
29
- ) -> syn:: Result < Self > ;
24
+ fn new ( input : ContainerInput , data : D , attributes : ContainerAttributes ) -> syn:: Result < Self > ;
30
25
31
26
/// This generates the complete code for a single versioned container.
32
27
///
37
32
fn generate_tokens ( & self ) -> TokenStream ;
38
33
}
39
34
35
+ /// This struct bundles values from [`DeriveInput`][1].
36
+ ///
37
+ /// [`DeriveInput`][1] cannot be used directly when constructing a
38
+ /// [`VersionedStruct`][2] or [`VersionedEnum`][3] because we run into borrow
39
+ /// issues caused by the match statement which extracts the data.
40
+ ///
41
+ /// [1]: syn::DeriveInput
42
+ /// [2]: crate::codegen::vstruct::VersionedStruct
43
+ /// [3]: crate::codegen::venum::VersionedEnum
44
+ pub ( crate ) struct ContainerInput {
45
+ pub ( crate ) original_attributes : Vec < Attribute > ,
46
+ pub ( crate ) visibility : Visibility ,
47
+ pub ( crate ) ident : Ident ,
48
+ }
49
+
40
50
/// Stores individual versions of a single container.
41
51
///
42
52
/// Each version tracks item actions, which describe if the item was added,
@@ -55,13 +65,17 @@ pub(crate) struct VersionedContainer<I> {
55
65
/// The ident, or name, of the versioned container.
56
66
pub ( crate ) ident : Ident ,
57
67
68
+ /// The visibility of the versioned container. Used to forward the
69
+ /// visibility during code generation.
70
+ pub ( crate ) visibility : Visibility ,
71
+
72
+ /// The original attributes that were added to the container.
73
+ pub ( crate ) original_attributes : Vec < Attribute > ,
74
+
58
75
/// The name of the container used in `From` implementations.
59
76
pub ( crate ) from_ident : Ident ,
60
77
61
78
/// Whether the [`From`] implementation generation should be skipped for all
62
79
/// versions of this container.
63
80
pub ( crate ) skip_from : bool ,
64
-
65
- /// The original attributes that were added to the container.
66
- pub ( crate ) original_attributes : Vec < Attribute > ,
67
81
}
0 commit comments