Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement d128! as a procedural macro #72

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

tari
Copy link

@tari tari commented Jul 13, 2022

This is basically a rewrite of #16 using procedural macros which were stabilized in the 2018 edition (rustc 1.31.0).

There are a few things that I haven't addressed yet, since I wanted to propose the concept before spending too much time on it:

  • The current decimal library can't export the new macro because the macro depends on it. This could be fixed by moving the existing implementation into a decimal-core crate, and making decimal a thin facade that re-exports everything from decimal-core alongside the macro from decimal-macros.
  • Because we're generating the underlying representation at compile-time, this might need special handling when cross-compiling because we may be calling to_raw_bytes and from_raw_bytes on different architectures.
  • Tests for error cases would be nice to have, but are best implemented by using proc_macro2 which I haven't done. At that point using quote to generate token streams might be easier (which I haven't done because not using it keeps the dependency count down).

This makes macro invocations free at runtime, whereas the old macro
delegated to from_str at runtime which has small but nonzero cost.

The concept is based on alkis#16
but completely rewritten with the newer (stable) procedural macros which
implies a requirement for rustc 1.31.0 (2018 edition). The
implementation uses the 2021 edition (rustc 1.56.0) for convenience.
@tari tari mentioned this pull request Jul 13, 2022
@trolleyman trolleyman mentioned this pull request Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant