Skip to content

Commit 461ba24

Browse files
committed
Apply more suggestions from code review, update documentation
1 parent 333d233 commit 461ba24

File tree

4 files changed

+25
-43
lines changed

4 files changed

+25
-43
lines changed

soa-derive-internal/src/iter.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use proc_macro2::TokenStream;
22
use quote::quote;
3-
use quote::TokenStreamExt;
43

54
use crate::input::{Input, TokenStreamIterator};
65
use crate::names;
@@ -80,7 +79,7 @@ pub fn derive(input: &Input) -> TokenStream {
8079
}
8180
}).expect("should be Some");
8281

83-
let mut generated = quote! {
82+
let generated = quote! {
8483
/// Iterator over
8584
#[doc = #doc_url]
8685
#[allow(missing_debug_implementations)]
@@ -134,14 +133,14 @@ pub fn derive(input: &Input) -> TokenStream {
134133
/// Get an iterator over the
135134
#[doc = #ref_doc_url]
136135
/// in this slice.
137-
pub fn iter(&self) -> <#name as ::soa_derive::SoAIter>::Iter {
136+
pub fn iter(&self) -> #iter_name {
138137
#iter_name(#create_iter)
139138
}
140139

141140
/// Get an iterator over the
142141
#[doc = #ref_doc_url]
143142
/// in this slice.
144-
pub fn into_iter(self) -> <#name as ::soa_derive::SoAIter<'a>>::Iter {
143+
pub fn into_iter(self) -> #iter_name<'a> {
145144
#iter_name(#create_into_iter)
146145
}
147146
}
@@ -189,7 +188,7 @@ pub fn derive(input: &Input) -> TokenStream {
189188
/// Get a mutable iterator over the
190189
#[doc = #ref_mut_doc_url]
191190
/// in this vector
192-
pub fn iter_mut(&mut self) -> <#name as ::soa_derive::SoAIter>::IterMut {
191+
pub fn iter_mut(&mut self) -> #iter_mut_name {
193192
self.as_mut_slice().into_iter()
194193
}
195194
}
@@ -198,21 +197,21 @@ pub fn derive(input: &Input) -> TokenStream {
198197
/// Get an iterator over the
199198
#[doc = #ref_doc_url]
200199
/// in this vector
201-
pub fn iter(&mut self) -> <#name as ::soa_derive::SoAIter>::Iter {
200+
pub fn iter(&mut self) -> #iter_name {
202201
self.as_ref().into_iter()
203202
}
204203

205204
/// Get a mutable iterator over the
206205
#[doc = #ref_mut_doc_url]
207206
/// in this vector
208-
pub fn iter_mut(&mut self) -> <#name as ::soa_derive::SoAIter>::IterMut {
207+
pub fn iter_mut(&mut self) -> #iter_mut_name {
209208
#iter_mut_name(#create_iter_mut)
210209
}
211210

212211
/// Get a mutable iterator over the
213212
#[doc = #ref_mut_doc_url]
214213
/// in this vector
215-
pub fn into_iter(self) -> <#name as ::soa_derive::SoAIter<'a>>::IterMut {
214+
pub fn into_iter(self) -> #iter_mut_name<'a> {
216215
#iter_mut_name(#create_mut_into_iter)
217216
}
218217
}
@@ -297,15 +296,9 @@ pub fn derive(input: &Input) -> TokenStream {
297296
self.extend(iter.into_iter().map(|item| item.to_owned()))
298297
}
299298
}
300-
};
301-
302-
{
303-
generated.append_all(quote! {
304299

305-
impl<'a> ::soa_derive::IntoSoAIter<'a, #name> for #slice_name<'a> {}
306-
307-
})
308-
}
300+
impl<'a> ::soa_derive::IntoSoAIter<'a, #name> for #slice_name<'a> {}
301+
};
309302

310303
return generated;
311304
}

soa-derive-internal/src/slice.rs

-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ pub fn derive(input: &Input) -> TokenStream {
5555
|ident, _| quote! { ::std::slice::from_raw_parts(data.#ident, len) },
5656
).collect::<Vec<_>>();
5757

58-
let iter_name = names::iter_name(name);
59-
6058
let mut generated = quote! {
6159
/// A slice of
6260
#[doc = #doc_url]
@@ -347,9 +345,6 @@ pub fn derive_mut(input: &Input) -> TokenStream {
347345
|ident, _| quote! { permutation.apply_slice_in_place(&mut self.#ident) },
348346
).collect::<Vec<_>>();
349347

350-
let iter_name = names::iter_name(name);
351-
let iter_mut_name = names::iter_mut_name(name);
352-
353348
let mut generated = quote! {
354349
/// A mutable slice of
355350
#[doc = #doc_url]

soa-derive-internal/src/vec.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ pub fn derive(input: &Input) -> TokenStream {
6767
|ident, _| quote! { ::std::mem::replace(&mut self.#ident[index], field) },
6868
).collect::<Vec<_>>();
6969

70-
let iter_name = names::iter_name(name);
71-
let iter_mut_name = names::iter_mut_name(name);
72-
7370
let mut generated = quote! {
7471
/// An analog to `
7572
#[doc = #vec_name_str]
@@ -471,19 +468,15 @@ pub fn derive(input: &Input) -> TokenStream {
471468
)*
472469
}
473470
}
474-
});
475471

476-
{
477-
generated.append_all(quote! {
478-
impl ::soa_derive::SoAAppendVec<#name> for #vec_name {
479-
fn extend_from_slice(&mut self, other: Self::Slice<'_>) {
480-
#(
481-
self.#fields_names.extend_from_slice(other.#fields_names);
482-
)*
483-
}
472+
impl ::soa_derive::SoAAppendVec<#name> for #vec_name {
473+
fn extend_from_slice(&mut self, other: Self::Slice<'_>) {
474+
#(
475+
self.#fields_names.extend_from_slice(other.#fields_names);
476+
)*
484477
}
485-
})
486-
}
478+
}
479+
});
487480
}
488481

489482
return generated;

src/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,13 @@
232232
//! `StructOfArray` does not provide a set of common operations by default. Thus if you wanted to use a `StructOfArray`
233233
//! type in a generic context, there is no way to guarantee to the type system that any methods are available.
234234
//!
235-
//! If the `generic_traits` feature is enabled, the attribute macro `#[generate_traits]` will generate
236-
//! implementations of [`SoAVec`], [`SoASlice`], and [`SoASliceMut`] for the respective `Vec`, `Slice`
237-
//! and `SliceMut` types.
238-
//!
239-
//! These rely on GATs, and so require Rust 1.65 or newer, and so this feature is disabled by default.
240-
//! Even when enabled, trait implementations are only generated by opting in with the `#[generate_traits]`
241-
//! attribute.
235+
//! This will also generate implementations of [`SoAVec`], [`SoASlice`], and [`SoASliceMut`] for the respective
236+
//! `Vec`, `Slice` and `SliceMut` types. These rely on GATs, and so require Rust 1.65 or newer.
242237
//!
243238
//! ```ignore
244239
//! # mod cheese {
245240
//! # use soa_derive::{StructOfArray, prelude::*};
246241
//! #[derive(StructOfArray)]
247-
//! #[generate_traits]
248242
//! pub struct Point {
249243
//! x: f32,
250244
//! y: f32,
@@ -415,8 +409,15 @@ macro_rules! soa_zip {
415409
}};
416410
}
417411

412+
413+
/// This trait is automatically implemented by the relevant generated by [`StructOfArray`].
414+
///
415+
/// Links a [`StructOfArray`] type to its raw pointer types, which is useful for generic
416+
/// programming.
418417
pub trait SoAPointers {
418+
/// The immutable pointer type for an SoA type
419419
type Ptr;
420+
/// The mutable pointer type for an SoA type
420421
type MutPtr;
421422
}
422423

0 commit comments

Comments
 (0)