This commit is contained in:
nora 2022-09-24 22:05:13 +02:00
parent 010126ce0b
commit 8862186a1f
7 changed files with 65 additions and 31 deletions

View file

@ -5,7 +5,7 @@ use std::cell::Cell;
use format::Parse as _;
use proc_macro::TokenStream;
use quote::{ToTokens, quote};
use quote::{quote, ToTokens};
use syn::{
parse::{Parse, ParseStream},
parse_macro_input, Expr, ExprAssign, ExprPath, Ident, LitStr, PathArguments, Result, Token,
@ -77,7 +77,9 @@ fn format_args_impl(input: Input) -> syn::Result<TokenStream> {
let current_position = Cell::new(0);
Ok(Scoped::new(&input, &fmt_parts, &current_position).to_token_stream().into())
Ok(Scoped::new(&input, &fmt_parts, &current_position)
.to_token_stream()
.into())
}
#[proc_macro]

View file

@ -5,7 +5,8 @@ use quote::{quote, ToTokens};
use crate::{
format::{
Align, Count, Format, FormatArg, FormatArgRef, FormatTrait, FormatterArgs, Piece, Sign,
Align, Count, DebugHex, Format, FormatArg, FormatArgRef, FormatTrait, FormatterArgs, Piece,
Sign,
},
Input,
};
@ -148,6 +149,14 @@ fn opt_value_tokens(scope: Scoped<'_, FormatterArgs<'_>>) -> TokenStream {
opts = quote! { #prefix::WithSignAwareZeroPad(#opts) };
}
if let Some(DebugHex::Lower) = args.debug_hex {
opts = quote! { #prefix::WithDebugLowerHex(#opts) };
}
if let Some(DebugHex::Upper) = args.debug_hex {
opts = quote! { #prefix::WithDebugUpperHex(#opts) };
}
opts
}
@ -197,6 +206,14 @@ fn opt_ty_tokens(scope: Scoped<'_, FormatterArgs<'_>>) -> TokenStream {
opts = quote! { #prefix::WithSignAwareZeroPad<#opts> };
}
if let Some(DebugHex::Lower) = args.debug_hex {
opts = quote! { #prefix::WithDebugLowerHex<#opts> };
}
if let Some(DebugHex::Upper) = args.debug_hex {
opts = quote! { #prefix::WithDebugUpperHex<#opts> };
}
opts
}