refactor: Factoring out attribtues

This commit is contained in:
2026-11-22 16:28:52 +01:00
parent bbf9c4d0a8
commit 42f85757d5
20 changed files with 767 additions and 85 deletions
+11 -11
View File
@@ -1,10 +1,10 @@
//! Derive macro for the `vxls_production::Attributes` trait.
//! Derive macro for the `vxls_attributes::Attributes` trait.
//!
//! # Example
//!
//! ```ignore
//! use bytemuck::{Pod, Zeroable};
//! use vxls_production::Attributes;
//! use vxls_attributes::Attributes;
//!
//! #[derive(Clone, Copy, PartialEq, Default, Pod, Zeroable, Attributes)]
//! #[repr(C)]
@@ -19,7 +19,7 @@
//! ```
//!
//! Each non-skipped field becomes one cache attribute, in declaration order.
//! The derive also implements `vxls_production::Attribute` for the struct by
//! The derive also implements `vxls_attributes::Attribute` for the struct by
//! averaging every field independently.
//!
//! Field options:
@@ -168,7 +168,7 @@ fn expand(input: DeriveInput) -> Result<TokenStream2>
};
descriptors.push(quote! {
::vxls_production::AttributeDescriptor {
::vxls_attributes::AttributeDescriptor {
label: #label,
word_count: (::core::mem::size_of::<#ty>() / 4) as u32,
semantic: #semantic,
@@ -176,15 +176,15 @@ fn expand(input: DeriveInput) -> Result<TokenStream2>
});
getters.push(quote! {
#index => ::vxls_production::bytemuck::bytes_of(&self.#name),
#index => ::vxls_attributes::bytemuck::bytes_of(&self.#name),
});
getters_mut.push(quote! {
#index => ::vxls_production::bytemuck::bytes_of_mut(&mut self.#name),
#index => ::vxls_attributes::bytemuck::bytes_of_mut(&mut self.#name),
});
averages.push(quote! {
#name: <#ty as ::vxls_production::Attribute>::average(
#name: <#ty as ::vxls_attributes::Attribute>::average(
&items
.iter()
.map(|item| item.#name)
@@ -201,10 +201,10 @@ fn expand(input: DeriveInput) -> Result<TokenStream2>
Ok(quote! {
#[automatically_derived]
impl ::vxls_production::Attributes for #ident
impl ::vxls_attributes::Attributes for #ident
{
const LAYOUT: ::vxls_production::AttributesLayout =
::vxls_production::AttributesLayout {
const LAYOUT: ::vxls_attributes::AttributesLayout =
::vxls_attributes::AttributesLayout {
attributes: &[ #(#descriptors),* ],
};
@@ -238,7 +238,7 @@ fn expand(input: DeriveInput) -> Result<TokenStream2>
}
#[automatically_derived]
impl ::vxls_production::Attribute for #ident
impl ::vxls_attributes::Attribute for #ident
{
fn average(items: &[Self]) -> Self
{