Skip to content

Commit 88a2e23

Browse files
curryyzhengLuthaf
authored andcommitted
doc: usage for soa_attr
1 parent b14eed6 commit 88a2e23

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ pub struct Cheese {
5454
}
5555
```
5656

57+
If you want to add attribute to a specific generated struct(such as
58+
`#[cfg_attr(test, derive(PartialEq))]` on `CheeseVec`), you can add an
59+
attribute `#[soa_attr(Vec, cfg_attr(test, derive(PartialEq)))]` to the
60+
struct declaration.
61+
62+
```rust
63+
#[derive(Debug, PartialEq, StructOfArray)]
64+
#[soa_attr(Vec, cfg_attr(test, derive(PartialEq)))]
65+
pub struct Cheese {
66+
pub smell: f64,
67+
pub color: (f64, f64, f64),
68+
pub with_mushrooms: bool,
69+
pub name: String,
70+
}
71+
```
72+
5773
## Usage and API
5874

5975
All the generated code have some generated documentation with it, so you

src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@
5151
//! }
5252
//! # }
5353
//! ```
54+
//!
55+
//! If you want to add attribute to a specific generated struct(such as
56+
//! `#[cfg_attr(test, derive(PartialEq))]` on `CheeseVec`), you can add an
57+
//! attribute `#[soa_attr(Vec, cfg_attr(test, derive(PartialEq)))]` to the
58+
//! struct declaration.
59+
//!
60+
//! ```
61+
//! # #[macro_use] extern crate soa_derive;
62+
//! # fn main() {
63+
//! #[derive(Debug, PartialEq, StructOfArray)]
64+
//! #[soa_attr(Vec, cfg_attr(test, derive(PartialEq)))]
65+
//! pub struct Cheese {
66+
//! pub smell: f64,
67+
//! pub color: (f64, f64, f64),
68+
//! pub with_mushrooms: bool,
69+
//! pub name: String,
70+
//! }
71+
//! # }
72+
//! ```
73+
//!
74+
//! Possible options for first argument of ``soa_attr`` attribute: `Vec`, `Slice`,
75+
//! `Ref` and `Ptr`.
5476
//!
5577
//! # Usage and API
5678
//!

0 commit comments

Comments
 (0)