Skip to content

Commit ca6edaf

Browse files
committed
fix: add a mod in doc test to workaround rust-lang/rust#83583
1 parent 1edd2fa commit ca6edaf

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

example/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
//! the code is generated by a single file:
33
//!
44
//! ```no_run
5-
//! #[macro_use]
65
//! extern crate soa_derive;
7-
//! # fn main() {
6+
//! # mod particle {
7+
//! #[macro_use]
8+
//! use soa_derive::StructOfArray;
89
//!
910
//! /// A basic Particle type
1011
//! #[derive(Debug, PartialEq, StructOfArray)]

src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
//! ```
66
//! # #[macro_use] extern crate soa_derive;
7-
//! # fn main() {
7+
//! # mod cheese {
88
//! #[derive(StructOfArray)]
99
//! pub struct Cheese {
1010
//! pub smell: f64,
@@ -40,7 +40,7 @@
4040
//!
4141
//! ```
4242
//! # #[macro_use] extern crate soa_derive;
43-
//! # fn main() {
43+
//! # mod cheese {
4444
//! #[derive(Debug, PartialEq, StructOfArray)]
4545
//! #[soa_derive(Debug, PartialEq)]
4646
//! pub struct Cheese {
@@ -59,7 +59,7 @@
5959
//!
6060
//! ```
6161
//! # #[macro_use] extern crate soa_derive;
62-
//! # fn main() {
62+
//! # mod cheese {
6363
//! #[derive(Debug, PartialEq, StructOfArray)]
6464
//! #[soa_attr(Vec, cfg_attr(test, derive(PartialEq)))]
6565
//! pub struct Cheese {
@@ -110,7 +110,7 @@
110110
//!
111111
//! ```no_run
112112
//! # #[macro_use] extern crate soa_derive;
113-
//! # fn main() {
113+
//! # mod cheese {
114114
//! # #[derive(Debug, PartialEq, StructOfArray)]
115115
//! # pub struct Cheese {
116116
//! # pub smell: f64,
@@ -119,6 +119,7 @@
119119
//! # pub name: String,
120120
//! # }
121121
//! # impl Cheese { fn new(name: &str) -> Cheese { unimplemented!() } }
122+
//! # fn main() {
122123
//! let mut vec = CheeseVec::new();
123124
//! vec.push(Cheese::new("stilton"));
124125
//! vec.push(Cheese::new("brie"));
@@ -130,6 +131,7 @@
130131
//! println!("this is {}, with a smell power of {}", cheese.name, cheese.smell);
131132
//! }
132133
//! # }
134+
//! # }
133135
//! ```
134136
//!
135137
//! One of the main advantage of the SoA layout is to be able to only load some
@@ -138,7 +140,7 @@
138140
//!
139141
//! ```no_run
140142
//! # #[macro_use] extern crate soa_derive;
141-
//! # fn main() {
143+
//! # mod cheese {
142144
//! # #[derive(Debug, PartialEq, StructOfArray)]
143145
//! # pub struct Cheese {
144146
//! # pub smell: f64,
@@ -147,6 +149,7 @@
147149
//! # pub name: String,
148150
//! # }
149151
//! # impl Cheese { fn new(name: &str) -> Cheese { unimplemented!() } }
152+
//! # fn main() {
150153
//! # let mut vec = CheeseVec::new();
151154
//! # vec.push(Cheese::new("stilton"));
152155
//! # vec.push(Cheese::new("brie"));
@@ -156,14 +159,15 @@
156159
//! println!("got cheese {}", name);
157160
//! }
158161
//! # }
162+
//! # }
159163
//! ```
160164
//!
161165
//! In order to iterate over multiple fields at the same time, one can use the
162166
//! [soa_zip!](macro.soa_zip.html) macro.
163167
//!
164168
//! ```no_run
165169
//! # #[macro_use] extern crate soa_derive;
166-
//! # fn main() {
170+
//! # mod cheese {
167171
//! # #[derive(Debug, PartialEq, StructOfArray)]
168172
//! # pub struct Cheese {
169173
//! # pub smell: f64,
@@ -172,6 +176,7 @@
172176
//! # pub name: String,
173177
//! # }
174178
//! # impl Cheese { fn new(name: &str) -> Cheese { unimplemented!() } }
179+
//! # fn main() {
175180
//! # let mut vec = CheeseVec::new();
176181
//! # vec.push(Cheese::new("stilton"));
177182
//! # vec.push(Cheese::new("brie"));
@@ -181,6 +186,7 @@
181186
//! *smell += 1.0;
182187
//! }
183188
//! # }
189+
//! # }
184190
//! ```
185191
//!
186192
//! ## Nested Struct of Arrays
@@ -190,6 +196,7 @@
190196
//! For example, the following code
191197
//!
192198
//! ```
199+
//! # mod cheese {
193200
//! # use soa_derive::StructOfArray;
194201
//! #[derive(StructOfArray)]
195202
//! pub struct Point {
@@ -202,6 +209,7 @@
202209
//! point: Point,
203210
//! mass: f32,
204211
//! }
212+
//! # }
205213
//! ```
206214
//!
207215
//! will generate structs that looks like this:
@@ -311,7 +319,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
311319
///
312320
/// ```
313321
/// # #[macro_use] extern crate soa_derive;
314-
/// # fn main() {
322+
/// # mod cheese {
315323
/// #[derive(StructOfArray)]
316324
/// struct Cheese {
317325
/// size: f64,
@@ -320,6 +328,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
320328
/// name: String,
321329
/// }
322330
///
331+
/// # fn main() {
323332
/// let mut vec = CheeseVec::new();
324333
/// // fill the vector
325334
///
@@ -334,6 +343,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
334343
/// *mass -= 1.0;
335344
/// }
336345
/// # }
346+
/// # }
337347
/// ```
338348
///
339349
/// The iterator can also work with external iterators. In this case, the
@@ -342,7 +352,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
342352
///
343353
/// ```
344354
/// # #[macro_use] extern crate soa_derive;
345-
/// # fn main() {
355+
/// # mod cheese {
346356
/// # #[derive(StructOfArray)]
347357
/// # struct Cheese {
348358
/// # size: f64,
@@ -351,13 +361,15 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
351361
/// # name: String,
352362
/// # }
353363
/// # #[derive(Debug)] struct Cellar;
364+
/// # fn main() {
354365
/// let mut vec = CheeseVec::new();
355366
/// let mut cellars = Vec::<Cellar>::new();
356367
///
357368
/// for (name, mass, cellar) in soa_zip!(&vec, [name, mass], &cellars) {
358369
/// println!("we have {} kg of {} in {:#?}", mass, name, cellar);
359370
/// }
360371
/// # }
372+
/// # }
361373
/// ```
362374
#[macro_export]
363375
macro_rules! soa_zip {

0 commit comments

Comments
 (0)