shori 0.0.4

Flexible parsing and transformation utilities for structured data. #[derive(Parser)] adds methods like .parse().json(), .toml(), .bin(), .map(), and .from() to simplify conversions using common wrappers like Arc, Mutex, Box, OnceCell, etc.
Documentation
use proc_macro2::TokenStream;
use quote::quote;
use syn::DeriveInput;

use mokuya::components::prelude::*;

pub fn generate_parse_ref_cell(input: &DeriveInput) -> TokenStream {
    let struct_name = get_struct_name(input);

    quote! {
        pub struct ParseRefCell(std::cell::RefCell<#struct_name>);

        impl ParseRefCell {
            /// Consumes self and returns the inner `RefCell` containing the struct.
            pub fn get(self) -> std::cell::RefCell<#struct_name> {
                self.0
            }

            /// Consumes self and returns an `Arc` wrapping the `RefCell` for shared ownership.
            pub fn arc(self) -> std::sync::Arc<std::cell::RefCell<#struct_name>> {
                std::sync::Arc::new(self.0)
            }

            /// Consumes self and returns a boxed `RefCell`.
            pub fn boxed(self) -> Box<std::cell::RefCell<#struct_name>> {
                Box::new(self.0)
            }

            /// Consumes self and returns an `UnsafeCell` wrapping the `RefCell`.
            pub fn unsafe_cell(self) -> std::cell::UnsafeCell<std::cell::RefCell<#struct_name>> {
                std::cell::UnsafeCell::new(self.0)
            }
        }
    }
}