4
4
//!
5
5
//! ```
6
6
//! # #[macro_use] extern crate soa_derive;
7
- //! # fn main() {
7
+ //! # mod cheese {
8
8
//! #[derive(StructOfArray)]
9
9
//! pub struct Cheese {
10
10
//! pub smell: f64,
40
40
//!
41
41
//! ```
42
42
//! # #[macro_use] extern crate soa_derive;
43
- //! # fn main() {
43
+ //! # mod cheese {
44
44
//! #[derive(Debug, PartialEq, StructOfArray)]
45
45
//! #[soa_derive(Debug, PartialEq)]
46
46
//! pub struct Cheese {
59
59
//!
60
60
//! ```
61
61
//! # #[macro_use] extern crate soa_derive;
62
- //! # fn main() {
62
+ //! # mod cheese {
63
63
//! #[derive(Debug, PartialEq, StructOfArray)]
64
64
//! #[soa_attr(Vec, cfg_attr(test, derive(PartialEq)))]
65
65
//! pub struct Cheese {
110
110
//!
111
111
//! ```no_run
112
112
//! # #[macro_use] extern crate soa_derive;
113
- //! # fn main() {
113
+ //! # mod cheese {
114
114
//! # #[derive(Debug, PartialEq, StructOfArray)]
115
115
//! # pub struct Cheese {
116
116
//! # pub smell: f64,
119
119
//! # pub name: String,
120
120
//! # }
121
121
//! # impl Cheese { fn new(name: &str) -> Cheese { unimplemented!() } }
122
+ //! # fn main() {
122
123
//! let mut vec = CheeseVec::new();
123
124
//! vec.push(Cheese::new("stilton"));
124
125
//! vec.push(Cheese::new("brie"));
130
131
//! println!("this is {}, with a smell power of {}", cheese.name, cheese.smell);
131
132
//! }
132
133
//! # }
134
+ //! # }
133
135
//! ```
134
136
//!
135
137
//! One of the main advantage of the SoA layout is to be able to only load some
138
140
//!
139
141
//! ```no_run
140
142
//! # #[macro_use] extern crate soa_derive;
141
- //! # fn main() {
143
+ //! # mod cheese {
142
144
//! # #[derive(Debug, PartialEq, StructOfArray)]
143
145
//! # pub struct Cheese {
144
146
//! # pub smell: f64,
147
149
//! # pub name: String,
148
150
//! # }
149
151
//! # impl Cheese { fn new(name: &str) -> Cheese { unimplemented!() } }
152
+ //! # fn main() {
150
153
//! # let mut vec = CheeseVec::new();
151
154
//! # vec.push(Cheese::new("stilton"));
152
155
//! # vec.push(Cheese::new("brie"));
156
159
//! println!("got cheese {}", name);
157
160
//! }
158
161
//! # }
162
+ //! # }
159
163
//! ```
160
164
//!
161
165
//! In order to iterate over multiple fields at the same time, one can use the
162
166
//! [soa_zip!](macro.soa_zip.html) macro.
163
167
//!
164
168
//! ```no_run
165
169
//! # #[macro_use] extern crate soa_derive;
166
- //! # fn main() {
170
+ //! # mod cheese {
167
171
//! # #[derive(Debug, PartialEq, StructOfArray)]
168
172
//! # pub struct Cheese {
169
173
//! # pub smell: f64,
172
176
//! # pub name: String,
173
177
//! # }
174
178
//! # impl Cheese { fn new(name: &str) -> Cheese { unimplemented!() } }
179
+ //! # fn main() {
175
180
//! # let mut vec = CheeseVec::new();
176
181
//! # vec.push(Cheese::new("stilton"));
177
182
//! # vec.push(Cheese::new("brie"));
181
186
//! *smell += 1.0;
182
187
//! }
183
188
//! # }
189
+ //! # }
184
190
//! ```
185
191
//!
186
192
//! ## Nested Struct of Arrays
190
196
//! For example, the following code
191
197
//!
192
198
//! ```
199
+ //! # mod cheese {
193
200
//! # use soa_derive::StructOfArray;
194
201
//! #[derive(StructOfArray)]
195
202
//! pub struct Point {
202
209
//! point: Point,
203
210
//! mass: f32,
204
211
//! }
212
+ //! # }
205
213
//! ```
206
214
//!
207
215
//! will generate structs that looks like this:
@@ -311,7 +319,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
311
319
///
312
320
/// ```
313
321
/// # #[macro_use] extern crate soa_derive;
314
- /// # fn main() {
322
+ /// # mod cheese {
315
323
/// #[derive(StructOfArray)]
316
324
/// struct Cheese {
317
325
/// size: f64,
@@ -320,6 +328,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
320
328
/// name: String,
321
329
/// }
322
330
///
331
+ /// # fn main() {
323
332
/// let mut vec = CheeseVec::new();
324
333
/// // fill the vector
325
334
///
@@ -334,6 +343,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
334
343
/// *mass -= 1.0;
335
344
/// }
336
345
/// # }
346
+ /// # }
337
347
/// ```
338
348
///
339
349
/// The iterator can also work with external iterators. In this case, the
@@ -342,7 +352,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
342
352
///
343
353
/// ```
344
354
/// # #[macro_use] extern crate soa_derive;
345
- /// # fn main() {
355
+ /// # mod cheese {
346
356
/// # #[derive(StructOfArray)]
347
357
/// # struct Cheese {
348
358
/// # size: f64,
@@ -351,13 +361,15 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
351
361
/// # name: String,
352
362
/// # }
353
363
/// # #[derive(Debug)] struct Cellar;
364
+ /// # fn main() {
354
365
/// let mut vec = CheeseVec::new();
355
366
/// let mut cellars = Vec::<Cellar>::new();
356
367
///
357
368
/// for (name, mass, cellar) in soa_zip!(&vec, [name, mass], &cellars) {
358
369
/// println!("we have {} kg of {} in {:#?}", mass, name, cellar);
359
370
/// }
360
371
/// # }
372
+ /// # }
361
373
/// ```
362
374
#[ macro_export]
363
375
macro_rules! soa_zip {
0 commit comments