This commit is contained in:
Dandaedre 2025-02-18 22:01:47 +01:00 committed by Dandaedre
parent 65502297b7
commit 36c7c8050b
1 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
// Workspace: more_fields_macro
// File: more_fields_macro/src/lib.rs
//! A very simple proc macro in chage of giving a field iterator over ("name","sql_type")
//! A very simple proc macro in chage of giving a field slice over ("name","sql_type")
//! This macro is a fork of the excellent work of : https://crates.io/crates/struct_iterable
//!
//! Other ressources include:
@ -57,15 +57,15 @@ pub fn derive_iterable(input: TokenStream) -> TokenStream {
let name_of_static_str = struct_name.to_string().to_ascii_uppercase() + "_ATTR_SLICE";
let name_of_static = Ident::new(&name_of_static_str, Span::call_site().into());
// static STATIC_FIELDS_OF_STRUCT_#struct_name: std::sync::LazyLock<Vec<(&'static str, &'static str)>> =
// std::sync::LazyLock::new(|| vec![]);
//
let expanded = quote! {
/// Derived implementation of a (attribute, type) slice
/// allowing a constant time serialisation & deserialisation into rusqlite
const #name_of_static: &[(&str, &str)] = &[
#(#fields_iter),*
];
impl FieldsAsSlice for #struct_name {
/// Gives a precompiled slice of the &[(fields: &str, sqlite_type: &str)]
fn attributes_slice<'a>() -> &'static [(&'static str, &'static str)] {
#name_of_static
}