Skip to content

Commit 81aeb97

Browse files
mangelatsLuthaf
authored andcommitted
f => Fix slice index methods
1 parent 92cd7d0 commit 81aeb97

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

soa-derive-internal/src/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,4 @@ pub fn derive(input: &Input) -> TokenStream {
659659
}
660660
}
661661
}
662-
}
662+
}

soa-derive-internal/src/slice.rs

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ pub fn derive(input: &Input) -> TokenStream {
153153
/// Similar to [`
154154
#[doc = #slice_name_str]
155155
/// ::get()`](https://doc.rust-lang.org/std/primitive.slice.html#method.get).
156-
pub fn get<'b: 'a, I>(&'b self, index: I) -> Option<I::RefOutput>
156+
pub fn get<'b, I>(&'b self, index: I) -> Option<I::RefOutput>
157157
where
158-
I: ::soa_derive::SoaIndex<#slice_name<'b>>
158+
I: ::soa_derive::SoaIndex<#slice_name<'b>>,
159+
'a: 'b
159160
{
160161
let slice: #slice_name<'b> = self.reborrow();
161162
index.get(slice)
@@ -164,24 +165,33 @@ pub fn derive(input: &Input) -> TokenStream {
164165
/// Similar to [`
165166
#[doc = #slice_name_str]
166167
/// ::get_unchecked()`](https://doc.rust-lang.org/std/primitive.slice.html#method.get_unchecked).
167-
pub unsafe fn get_unchecked<'b: 'a, I>(&'b self, index: I) -> I::RefOutput
168+
pub unsafe fn get_unchecked<'b, I>(&'b self, index: I) -> I::RefOutput
168169
where
169-
I: ::soa_derive::SoaIndex<#slice_name<'b>>
170+
I: ::soa_derive::SoaIndex<#slice_name<'b>>,
171+
'a: 'b
170172
{
171173
let slice: #slice_name<'b> = self.reborrow();
172174
index.get_unchecked(slice)
173175
}
174176

175-
pub fn index<'b: 'a, I>(&'b self, index: I) -> I::RefOutput
177+
/// Similar to [`std::ops::Index` trait](https://doc.rust-lang.org/std/ops/trait.Index.html) on
178+
#[doc = #slice_name_str]
179+
/// .
180+
/// This is required because we cannot implement that trait.
181+
pub fn index<'b, I>(&'b self, index: I) -> I::RefOutput
176182
where
177-
I: ::soa_derive::SoaIndex<#slice_name<'b>>
183+
I: ::soa_derive::SoaIndex<#slice_name<'b>>,
184+
'a: 'b
178185
{
179186
let slice: #slice_name<'b> = self.reborrow();
180187
index.index(slice)
181188
}
182189

183190
/// Reborrows the slices in a more narrower lifetime
184-
pub fn reborrow<'b: 'a>(&'b self) -> #slice_name<'b> {
191+
pub fn reborrow<'b>(&'b self) -> #slice_name<'b>
192+
where
193+
'a: 'b
194+
{
185195
#slice_name {
186196
#(#fields_names_1: &self.#fields_names_2,)*
187197
}
@@ -396,9 +406,10 @@ pub fn derive_mut(input: &Input) -> TokenStream {
396406
/// Similar to [`
397407
#[doc = #slice_name_str]
398408
/// ::get()`](https://doc.rust-lang.org/std/primitive.slice.html#method.get).
399-
pub fn get<'b: 'a, I>(&'b self, index: I) -> Option<I::RefOutput>
409+
pub fn get<'b, I>(&'b self, index: I) -> Option<I::RefOutput>
400410
where
401-
I: ::soa_derive::SoaIndex<#slice_name<'b>>
411+
I: ::soa_derive::SoaIndex<#slice_name<'b>>,
412+
'a: 'b
402413
{
403414
let slice: #slice_name<'b> = self.as_slice();
404415
index.get(slice)
@@ -407,17 +418,24 @@ pub fn derive_mut(input: &Input) -> TokenStream {
407418
/// Similar to [`
408419
#[doc = #slice_name_str]
409420
/// ::get_unchecked()`](https://doc.rust-lang.org/std/primitive.slice.html#method.get_unchecked).
410-
pub unsafe fn get_unchecked<'b: 'a, I>(&'b self, index: I) -> I::RefOutput
421+
pub unsafe fn get_unchecked<'b, I>(&'b self, index: I) -> I::RefOutput
411422
where
412-
I: ::soa_derive::SoaIndex<#slice_name<'b>>
423+
I: ::soa_derive::SoaIndex<#slice_name<'b>>,
424+
'a: 'b
413425
{
414426
let slice: #slice_name<'b> = self.as_slice();
415427
index.get_unchecked(slice)
416428
}
417429

418-
pub fn index<'b: 'a, I>(&'b self, index: I) -> I::RefOutput
430+
431+
/// Similar to [`std::ops::Index` trait](https://doc.rust-lang.org/std/ops/trait.Index.html) on
432+
#[doc = #slice_name_str]
433+
/// .
434+
/// This is required because we cannot implement that trait.
435+
pub fn index<'b, I>(&'b self, index: I) -> I::RefOutput
419436
where
420-
I: ::soa_derive::SoaIndex<#slice_name<'b>>
437+
I: ::soa_derive::SoaIndex<#slice_name<'b>>,
438+
'a: 'b
421439
{
422440
let slice: #slice_name<'b> = self.as_slice();
423441
index.index(slice)
@@ -426,44 +444,59 @@ pub fn derive_mut(input: &Input) -> TokenStream {
426444
/// Similar to [`
427445
#[doc = #slice_name_str]
428446
/// ::get_mut()`](https://doc.rust-lang.org/std/primitive.slice.html#method.get_mut).
429-
pub fn get_mut<'b: 'a, I>(&'b mut self, index: I) -> Option<I::MutOutput>
447+
pub fn get_mut<'b, I>(&'b mut self, index: I) -> Option<I::MutOutput>
430448
where
431-
I: ::soa_derive::SoaMutIndex<#slice_mut_name<'b>>
449+
I: ::soa_derive::SoaMutIndex<#slice_mut_name<'b>>,
450+
'a: 'b
432451
{
433-
let slice: #slice_mut_name<'b> = self.reborrow();
452+
let slice: #slice_mut_name<'b> = #slice_mut_name {
453+
#(#fields_names_1: &mut *self.#fields_names_2,)*
454+
};
434455
index.get_mut(slice)
435456
}
436457

437458
/// Similar to [`
438459
#[doc = #slice_name_str]
439460
/// ::get_unchecked_mut()`](https://doc.rust-lang.org/std/primitive.slice.html#method.get_unchecked_mut).
440-
pub unsafe fn get_unchecked_mut<'b: 'a, I>(&'b mut self, index: I) -> I::MutOutput
461+
pub unsafe fn get_unchecked_mut<'b, I>(&'b mut self, index: I) -> I::MutOutput
441462
where
442-
I: ::soa_derive::SoaMutIndex<#slice_mut_name<'b>>
463+
I: ::soa_derive::SoaMutIndex<#slice_mut_name<'b>>,
464+
'a: 'b
443465
{
444466
let slice: #slice_mut_name<'b> = self.reborrow();
445467
index.get_unchecked_mut(slice)
446468
}
447469

448-
pub fn index_mut<'b: 'a, I>(&'b mut self, index: I) -> I::MutOutput
470+
/// Similar to [`std::ops::IndexMut` trait](https://doc.rust-lang.org/std/ops/trait.IndexMut.html) on
471+
#[doc = #slice_name_str]
472+
/// .
473+
/// This is required because we cannot implement that trait.
474+
pub fn index_mut<'b, I>(&'b mut self, index: I) -> I::MutOutput
449475
where
450-
I: ::soa_derive::SoaMutIndex<#slice_mut_name<'b>>
476+
I: ::soa_derive::SoaMutIndex<#slice_mut_name<'b>>,
477+
'a: 'b
451478
{
452479
let slice: #slice_mut_name<'b> = self.reborrow();
453480
index.index_mut(slice)
454481
}
455482

456483
/// Returns a non-mutable slice from this mutable slice.
457-
pub fn as_slice<'b: 'a>(&'b self) -> #slice_name<'b> {
484+
pub fn as_slice<'b>(&'b self) -> #slice_name<'b>
485+
where
486+
'a: 'b
487+
{
458488
#slice_name {
459489
#(#fields_names_1: &self.#fields_names_2,)*
460490
}
461491
}
462492

463493
/// Reborrows the slices in a more narrower lifetime
464-
pub fn reborrow<'b: 'a>(&'b mut self) -> #slice_mut_name<'b> {
494+
pub fn reborrow<'b>(&'b mut self) -> #slice_mut_name<'b>
495+
where
496+
'a: 'b
497+
{
465498
#slice_mut_name {
466-
#(#fields_names_1: &mut self.#fields_names_2,)*
499+
#(#fields_names_1: &mut *self.#fields_names_2,)*
467500
}
468501
}
469502

0 commit comments

Comments
 (0)