Skip to content

Commit 63f2157

Browse files
committed
feat: soa_attr for Ptr/PtrMut's field
1 parent 392d0c9 commit 63f2157

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

soa-derive-internal/src/ptr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub fn derive(input: &Input) -> TokenStream {
3838
.map(|field| format!("A mutable pointer to a `{0}` from a [`{1}`](struct.{1}.html)", field, vec_name))
3939
.collect::<Vec<_>>();
4040

41+
let field_attrs = input.field_attrs.iter()
42+
.map(|attr| &attr.ptr).collect::<Vec<_>>();
43+
44+
let mut_field_attrs = input.field_attrs.iter()
45+
.map(|attr| &attr.ptr_mut).collect::<Vec<_>>();
46+
4147
quote! {
4248
/// An analog of a pointer to
4349
#[doc = #doc_url]
@@ -47,6 +53,7 @@ pub fn derive(input: &Input) -> TokenStream {
4753
#visibility struct #ptr_name {
4854
#(
4955
#[doc = #fields_doc]
56+
#(#[#field_attrs])*
5057
pub #fields_names_1: *const #fields_types,
5158
)*
5259
}
@@ -59,6 +66,7 @@ pub fn derive(input: &Input) -> TokenStream {
5966
#visibility struct #ptr_mut_name {
6067
#(
6168
#[doc = #fields_mut_doc]
69+
#(#[#mut_field_attrs])*
6270
pub #fields_names_1: *mut #fields_types,
6371
)*
6472
}

tests/soa_attr.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ pub struct Point {
3434
#[soa_attr(RefMut, deprecated)]
3535
pub x: f32,
3636
#[soa_attr(SliceMut, deprecated)]
37+
#[soa_attr(Ptr, deprecated)]
3738
pub y: f32,
3839
#[soa_attr(Vec, serde(skip))]
3940
#[soa_attr(Ref, deprecated)]
41+
#[soa_attr(PtrMut, deprecated)]
4042
pub meta: bool
4143
}
4244

@@ -59,23 +61,35 @@ fn serde_skip_test() -> Result<(), serde_json::Error> {
5961
{
6062
let slice = soa.as_slice();
6163
let _ = slice.x[0]; // Should have a deprecate warning
62-
let _ = slice.y[0]; // Should not have a deprecate warning
63-
let _ = slice.meta[0]; // Should not have a deprecate warning
64+
let _ = slice.y[0];
65+
let _ = slice.meta[0];
6466

6567
let ref_ = slice.get(1).unwrap();
66-
let _ = ref_.x; // Should not have a deprecate warning
67-
let _ = ref_.y; // Should not have a deprecate warning
68+
let _ = ref_.x;
69+
let _ = ref_.y;
6870
let _ = ref_.meta; // Should have a deprecate warning
71+
72+
let ptr = ref_.as_ptr();
73+
let _ = ptr.x;
74+
let _ = ptr.y; // Should have a deprecate warning
75+
let _ = ptr.meta;
76+
6977
}
7078
{
7179
let mut slice = soa.as_mut_slice();
80+
let _ = slice.x[0];
7281
let _ = slice.y[0]; // Should have a deprecate warning
73-
let _ = slice.x[0]; // Should not have a deprecate warning
82+
let _ = slice.meta[0];
7483

7584
let ref_mut = slice.get_mut(1).unwrap();
7685
let _ = ref_mut.x; // Should have a deprecate warning
77-
let _ = ref_mut.y; // Should not have a deprecate warning
78-
let _ = ref_mut.meta; // Should not have a deprecate warning
86+
let _ = ref_mut.y;
87+
let _ = ref_mut.meta;
88+
89+
let ptr_mut = ref_mut.as_ptr();
90+
let _ = ptr_mut.x; // Should not have a deprecate warning
91+
let _ = ptr_mut.y; // Should not have a deprecate warning
92+
let _ = ptr_mut.meta; // Should have a deprecate warning
7993
}
8094
Ok(())
8195
}

0 commit comments

Comments
 (0)