Skip to content

Commit

Permalink
Drop internal_fn_datatype!() proc macro
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Jul 10, 2024
1 parent ca9aa4b commit 8d469e7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 62 deletions.
40 changes: 0 additions & 40 deletions specta-macros/src/internal_fn_datatype.rs

This file was deleted.

15 changes: 0 additions & 15 deletions specta-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
html_favicon_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png"
)]

#[cfg(feature = "DO_NOT_USE_function")]
mod internal_fn_datatype;
#[cfg(feature = "DO_NOT_USE_function")]
mod specta;
mod r#type;
Expand All @@ -28,16 +26,3 @@ pub fn specta(
) -> proc_macro::TokenStream {
specta::attribute(item).unwrap_or_else(|err| err.into_compile_error().into())
}

#[proc_macro]
#[doc(hidden)]
#[cfg(feature = "DO_NOT_USE_function")]
pub fn internal_fn_datatype(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
use syn::parse_macro_input;

internal_fn_datatype::proc_macro(parse_macro_input!(
input as internal_fn_datatype::FnDatatypeInput
))
.unwrap_or_else(|err| err.into_compile_error())
.into()
}
4 changes: 2 additions & 2 deletions specta-macros/src/specta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ pub fn attribute(item: proc_macro::TokenStream) -> syn::Result<proc_macro::Token
#maybe_macro_export
#[doc(hidden)] // We take in `$function` from the invocation so we have `name::<concrete_generics_types>`
macro_rules! #wrapper {
(@export_fn; $function:path) => {
(@export_fn) => {
fn export(type_map: &mut #crate_ref::TypeMap) -> #crate_ref::function::FunctionDataType {
specta::internal::get_fn_datatype(
$function as fn(#(#arg_signatures),*) -> _,
$function_name as fn(#(#arg_signatures),*) -> _,
#function_asyncness,
#function_name_str.into(),
type_map,
Expand Down
4 changes: 2 additions & 2 deletions specta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ derive = ["dep:specta-macros"]

#! Features
## Support for exporting the types of Rust functions.
function = ["serde", "specta-macros/DO_NOT_USE_function"]
function = ["specta-macros/DO_NOT_USE_function", "dep:paste"] # TODO: Why does this depend on `serde`???

#! Compatability
## Support for [serde](https://serde.rs)
Expand Down Expand Up @@ -85,8 +85,8 @@ workspace = true

[dependencies]
specta-macros = { version = "=2.0.0-rc.15", optional = true, path = "../specta-macros" }
paste = { version = "1", optional = true }
thiserror = "1.0.61"
paste = "1.0.15"

# TODO: To be deprecated
specta1 = { package = "specta", version = "1", optional = true, default-features = false }
Expand Down
12 changes: 10 additions & 2 deletions specta/src/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ pub(crate) use result::*;
/// ```
#[macro_export]
macro_rules! fn_datatype {
// TODO: Removing `type_map`???
($function:path) => {{
let mut type_map = $crate::TypeMap::default();
let mut type_map = specta::TypeMap::default();
$crate::fn_datatype!(type_map; $function)
}};
($type_map:ident; $function:path) => {{
let type_map: &mut $crate::TypeMap = &mut $type_map;
$crate::internal::internal_fn_datatype!($function);

// This defines `export` function
$crate::internal::paste! { [<__specta__fn__ $function>]!(@export_fn) }

// `let` is to workaround: error: macro expansion ignores token `;` and any following
let result = export(type_map);

result
}};
}
Expand Down Expand Up @@ -75,6 +82,7 @@ macro_rules! fn_datatype {
/// ````
#[macro_export]
macro_rules! collect_functions {
// TODO: Removing `type_map`???
($type_map:ident; $($command:path),* $(,)?) => {{
let mut type_map: $crate::TypeMap = $type_map;
([$($crate::fn_datatype!(type_map; $command)),*]
Expand Down
2 changes: 1 addition & 1 deletion specta/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::borrow::Cow;
pub mod interop;

#[cfg(feature = "function")]
pub use specta_macros::internal_fn_datatype;
pub use paste::paste;

use crate::{
DataType, EnumVariants, Field, GenericType, Generics, List, Map, SpectaID, StructFields, Type,
Expand Down

0 comments on commit 8d469e7

Please sign in to comment.