Skip to content

Commit 4c99688

Browse files
committed
doc: update usage for nested_soa, replace no_run by ignore
1 parent d50eb1d commit 4c99688

File tree

3 files changed

+81
-11
lines changed

3 files changed

+81
-11
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,41 @@ for (name, smell, color) in soa_zip!(vec, [name, mut smell, color]) {
138138
}
139139
```
140140

141+
## Nested Struct of Arrays
142+
143+
In order to nest a struct of arrays inside another struct of arrays, one can use the `#[nested_soa]` attribute.
144+
145+
For example, the following code
146+
147+
```rust
148+
#[derive(StructOfArray)]
149+
pub struct Point {
150+
x: f32,
151+
y: f32,
152+
}
153+
#[derive(StructOfArray)]
154+
pub struct Particle {
155+
#[nested_soa]
156+
point: Point,
157+
mass: f32,
158+
}
159+
```
160+
161+
will generate structs that looks like this:
162+
163+
```rust
164+
pub struct PointVec {
165+
x: Vec<f32>,
166+
y: Vec<f32>,
167+
}
168+
pub struct ParticleVec {
169+
point: PointVec, // rather than Vec<Point>
170+
mass: Vec<f32>
171+
}
172+
```
173+
174+
All helper structs will be also nested, for example `PointSlice` will be nested in `ParticleSlice`.
175+
141176
## Documentation
142177

143178
Please see http://lumol.org/soa-derive/soa_derive_example/ for a small

example/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! This crate is an example for the [`soa_derive`] crate functionalities. All
22
//! the code is generated by a single file:
33
//!
4-
//! ```no_run
4+
//! ```ignore
55
//! #[macro_use]
66
//! extern crate soa_derive;
77
//! # fn main() {
88
//!
99
//! /// A basic Particle type
1010
//! #[derive(Debug, PartialEq, StructOfArray)]
11-
//! #[soa_derive = "Debug, PartialEq"]
11+
//! #[soa_derive(Debug, PartialEq)]
1212
//! pub struct Particle {
1313
//! /// Mass of the particle
1414
//! pub mass: f64,

src/lib.rs

+44-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! automatically generate code from a given struct `T` that allow to replace
33
//! `Vec<T>` with a struct of arrays. For example, the following code
44
//!
5-
//! ```
5+
//! ```ignore
66
//! # #[macro_use] extern crate soa_derive;
77
//! # fn main() {
88
//! #[derive(StructOfArray)]
@@ -17,7 +17,7 @@
1717
//!
1818
//! will generate a `CheeseVec` struct that looks like this:
1919
//!
20-
//! ```
20+
//! ```ignore
2121
//! pub struct CheeseVec {
2222
//! pub smell: Vec<f64>,
2323
//! pub color: Vec<(f64, f64, f64)>,
@@ -38,7 +38,7 @@
3838
//! (such as `Debug` or `PartialEq`), you can add an attribute `#[soa_derive =
3939
//! "Debug, PartialEq"]` to the struct declaration.
4040
//!
41-
//! ```
41+
//! ```ignore
4242
//! # #[macro_use] extern crate soa_derive;
4343
//! # fn main() {
4444
//! #[derive(Debug, PartialEq, StructOfArray)]
@@ -57,7 +57,7 @@
5757
//! attribute `#[soa_attr(Vec, cfg_attr(test, derive(PartialEq)))]` to the
5858
//! struct declaration.
5959
//!
60-
//! ```
60+
//! ```ignore
6161
//! # #[macro_use] extern crate soa_derive;
6262
//! # fn main() {
6363
//! #[derive(Debug, PartialEq, StructOfArray)]
@@ -108,7 +108,7 @@
108108
//!
109109
//! It is possible to iterate over the values in a `CheeseVec`
110110
//!
111-
//! ```no_run
111+
//! ```ignore
112112
//! # #[macro_use] extern crate soa_derive;
113113
//! # fn main() {
114114
//! # #[derive(Debug, PartialEq, StructOfArray)]
@@ -136,7 +136,7 @@
136136
//! fields from memory when iterating over the vector. In order to do so, one
137137
//! can manually pick the needed fields:
138138
//!
139-
//! ```no_run
139+
//! ```ignore
140140
//! # #[macro_use] extern crate soa_derive;
141141
//! # fn main() {
142142
//! # #[derive(Debug, PartialEq, StructOfArray)]
@@ -161,7 +161,7 @@
161161
//! In order to iterate over multiple fields at the same time, one can use the
162162
//! [soa_zip!](macro.soa_zip.html) macro.
163163
//!
164-
//! ```no_run
164+
//! ```ignore
165165
//! # #[macro_use] extern crate soa_derive;
166166
//! # fn main() {
167167
//! # #[derive(Debug, PartialEq, StructOfArray)]
@@ -182,6 +182,41 @@
182182
//! }
183183
//! # }
184184
//! ```
185+
//!
186+
//! ## Nested Struct of Arrays
187+
//!
188+
//! In order to nest a struct of arrays inside another struct of arrays, one can use the `#[nested_soa]` attribute.
189+
//!
190+
//! For example, the following code
191+
//!
192+
//! ```ignore
193+
//! #[derive(StructOfArray)]
194+
//! pub struct Point {
195+
//! x: f32,
196+
//! y: f32,
197+
//! }
198+
//! #[derive(StructOfArray)]
199+
//! pub struct Particle {
200+
//! #[nested_soa]
201+
//! point: Point,
202+
//! mass: f32,
203+
//! }
204+
//! ```
205+
//!
206+
//! will generate structs that looks like this:
207+
//!
208+
//! ```ignore
209+
//! pub struct PointVec {
210+
//! x: Vec<f32>,
211+
//! y: Vec<f32>,
212+
//! }
213+
//! pub struct ParticleVec {
214+
//! point: PointVec, // rather than Vec<Point>
215+
//! mass: Vec<f32>
216+
//! }
217+
//! ```
218+
//!
219+
//! All helper structs will be also nested, for example `PointSlice` will be nested in `ParticleSlice`.
185220
186221
// The proc macro is implemented in soa_derive_internal, and re-exported by this
187222
// crate. This is because a single crate can not define both a proc macro and a
@@ -280,7 +315,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
280315
/// to the fields, which can be mutable references if the field name is prefixed
281316
/// with `mut`.
282317
///
283-
/// ```
318+
/// ```ignore
284319
/// # #[macro_use] extern crate soa_derive;
285320
/// # fn main() {
286321
/// #[derive(StructOfArray)]
@@ -311,7 +346,7 @@ pub trait SoAIndexMut<T>: private_soa_indexes::Sealed {
311346
/// iterator will yields elements until any of the fields or one external
312347
/// iterator returns None.
313348
///
314-
/// ```
349+
/// ```ignore
315350
/// # #[macro_use] extern crate soa_derive;
316351
/// # fn main() {
317352
/// # #[derive(StructOfArray)]

0 commit comments

Comments
 (0)