@@ -52,9 +52,9 @@ const DATA_SIZE: usize = 1;
52
52
/// - `data`: The top level crate information and documentation
53
53
/// - `included`: The rest of the crate information and documentation
54
54
#[ derive( Serialize , Debug ) ]
55
- pub struct Documentation < ' a > {
56
- data : Option < Document < ' a > > ,
57
- included : Option < Vec < Document < ' a > > > ,
55
+ pub struct Documentation {
56
+ data : Option < Document > ,
57
+ included : Option < Vec < Document > > ,
58
58
}
59
59
60
60
/// A sub type of the `Documentation` struct. It contains the majority of the data. It can be used
@@ -68,12 +68,12 @@ pub struct Documentation<'a> {
68
68
/// - `relationships`: An optional field used to show the relationship between the crate to the
69
69
/// otheritems in the crate
70
70
#[ derive( Serialize , Debug ) ]
71
- pub struct Document < ' a > {
71
+ pub struct Document {
72
72
#[ serde( rename = "type" ) ]
73
- ty : & ' a str ,
74
- id : & ' a str ,
75
- attributes : HashMap < & ' a str , & ' a str > ,
76
- relationships : Option < HashMap < & ' a str , HashMap < & ' a str , Vec < Data < ' a > > > > > ,
73
+ ty : String ,
74
+ id : String ,
75
+ attributes : HashMap < String , String > ,
76
+ relationships : Option < HashMap < String , HashMap < String , Vec < Data > > > > ,
77
77
}
78
78
79
79
/// Used to populate the `relationships` `data` field in the serialized JSON
@@ -83,13 +83,13 @@ pub struct Document<'a> {
83
83
/// - `ty`: The type of the the item (e.g. "crate", "function", "enum", etc.)
84
84
/// - `id`: The unique identifier associated with this item
85
85
#[ derive( Serialize , Debug ) ]
86
- pub struct Data < ' a > {
86
+ pub struct Data {
87
87
#[ serde( rename = "type" ) ]
88
- ty : & ' a str ,
89
- id : & ' a str ,
88
+ ty : String ,
89
+ id : String ,
90
90
}
91
91
92
- impl < ' a > Documentation < ' a > {
92
+ impl Documentation {
93
93
/// Create an empty `Documentation` struct
94
94
pub fn new ( ) -> Self {
95
95
Self {
@@ -100,56 +100,56 @@ impl<'a> Documentation<'a> {
100
100
101
101
/// Set the `data` field of a `Documentation` struct to the value passed into the
102
102
/// `data` argument
103
- pub fn data ( mut self , data : Document < ' a > ) -> Self {
103
+ pub fn data ( mut self , data : Document ) -> Self {
104
104
self . data = Some ( data) ;
105
105
self
106
106
}
107
107
108
108
/// Set the `included` field of a `Documentation` struct to the value passed into the
109
109
/// `included` argument
110
- pub fn included ( mut self , included : Vec < Document < ' a > > ) -> Self {
110
+ pub fn included ( mut self , included : Vec < Document > ) -> Self {
111
111
self . included = Some ( included) ;
112
112
self
113
113
}
114
114
}
115
115
116
- impl < ' a > Document < ' a > {
116
+ impl Document {
117
117
/// Create an empty `Document` struct
118
118
pub fn new ( ) -> Self {
119
119
Self {
120
- ty : "" ,
121
- id : "" ,
120
+ ty : String :: new ( ) ,
121
+ id : String :: new ( ) ,
122
122
attributes : HashMap :: new ( ) ,
123
123
relationships : None ,
124
124
}
125
125
}
126
126
127
127
/// Set the `ty` field of a `Document` struct to the value passed into the
128
128
/// `t` argument
129
- pub fn ty ( mut self , t : & ' a str ) -> Self {
129
+ pub fn ty ( mut self , t : String ) -> Self {
130
130
self . ty = t;
131
131
self
132
132
}
133
133
134
134
/// Set the `id` field of a `Document` struct to the value passed into the
135
135
/// `id` argument
136
- pub fn id ( mut self , id : & ' a str ) -> Self {
136
+ pub fn id ( mut self , id : String ) -> Self {
137
137
self . id = id;
138
138
self
139
139
}
140
140
141
141
/// Insert an attribute for the `attribute` field of a `Document` struct. If the current
142
142
/// `attribute` exists it'll be overwritten with the given value, otherwise it'll just be
143
143
/// created for the first time.
144
- pub fn attributes ( mut self , attribute : & ' a str , value : & ' a str ) -> Self {
144
+ pub fn attributes ( mut self , attribute : String , value : String ) -> Self {
145
145
self . attributes . insert ( attribute, value) ;
146
146
self
147
147
}
148
148
149
149
/// Insert a relationship for the `relationships` field of a `Document` struct. If the current
150
150
/// `ty` exists it'll be overwritten with the given `data` value, otherwise it'll just be
151
151
/// created for the first time.
152
- pub fn relationships ( & mut self , ty : & ' a str , data : Vec < Data < ' a > > ) {
152
+ pub fn relationships ( & mut self , ty : String , data : Vec < Data > ) {
153
153
match self . relationships {
154
154
// The code below allows us to handle with ease the fact we have data structured like:
155
155
//
@@ -181,7 +181,7 @@ impl<'a> Document<'a> {
181
181
// it to the `Document`.
182
182
None => {
183
183
let mut data_map = HashMap :: with_capacity ( DATA_SIZE ) ;
184
- data_map. insert ( "data" , data) ;
184
+ data_map. insert ( String :: from ( "data" ) , data) ;
185
185
186
186
let mut relationships = HashMap :: with_capacity ( METADATA_SIZE ) ;
187
187
relationships. insert ( ty, data_map) ;
@@ -191,28 +191,31 @@ impl<'a> Document<'a> {
191
191
// type, etc.) and the data.
192
192
Some ( ref mut relationships) => {
193
193
let mut data_map = HashMap :: with_capacity ( DATA_SIZE ) ;
194
- data_map. insert ( "data" , data) ;
194
+ data_map. insert ( String :: from ( "data" ) , data) ;
195
195
196
196
relationships. insert ( ty, data_map) ;
197
197
}
198
198
}
199
199
}
200
200
}
201
201
202
- impl < ' a > Data < ' a > {
202
+ impl Data {
203
203
/// Create a new empty `Data` struct
204
204
pub fn new ( ) -> Self {
205
- Self { ty : "" , id : "" }
205
+ Self {
206
+ ty : String :: new ( ) ,
207
+ id : String :: new ( ) ,
208
+ }
206
209
}
207
210
208
211
/// Set the `ty` field of `Data` to the value passed to the `t` argument
209
- pub fn ty ( mut self , t : & ' a str ) -> Self {
212
+ pub fn ty ( mut self , t : String ) -> Self {
210
213
self . ty = t;
211
214
self
212
215
}
213
216
214
217
/// Set the `id` field of `Data` to the value passed to the `id` argument
215
- pub fn id ( mut self , id : & ' a str ) -> Self {
218
+ pub fn id ( mut self , id : String ) -> Self {
216
219
self . id = id;
217
220
self
218
221
}
0 commit comments