diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/enum-ordinalize-derive/src/int_wrapper.rs | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/enum-ordinalize-derive/src/int_wrapper.rs')
| -rw-r--r-- | vendor/enum-ordinalize-derive/src/int_wrapper.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/enum-ordinalize-derive/src/int_wrapper.rs b/vendor/enum-ordinalize-derive/src/int_wrapper.rs new file mode 100644 index 00000000..3747325d --- /dev/null +++ b/vendor/enum-ordinalize-derive/src/int_wrapper.rs @@ -0,0 +1,57 @@ +use proc_macro2::{Literal, TokenStream}; +use quote::{quote, ToTokens, TokenStreamExt}; +use syn::Expr; + +use crate::int128::Int128; + +pub(crate) enum IntWrapper { + Integer(Int128), + Constant(Expr, usize), +} + +impl From<Int128> for IntWrapper { + #[inline] + fn from(v: Int128) -> IntWrapper { + Self::Integer(v) + } +} + +impl From<i128> for IntWrapper { + #[inline] + fn from(v: i128) -> IntWrapper { + Self::Integer(Int128::from(v)) + } +} + +impl From<(&Expr, usize)> for IntWrapper { + #[inline] + fn from((expr, counter): (&Expr, usize)) -> IntWrapper { + Self::Constant(expr.clone(), counter) + } +} + +impl ToTokens for IntWrapper { + #[inline] + fn to_tokens(&self, tokens: &mut TokenStream) { + match self { + Self::Integer(v) => { + let lit = match v { + Int128::Signed(i) => Literal::i128_unsuffixed(*i), + Int128::Unsigned(u) => Literal::u128_unsuffixed(*u), + }; + + tokens.append(lit); + }, + Self::Constant(expr, counter) => { + let counter = *counter; + + if counter > 0 { + tokens.extend(quote!(#expr +)); + tokens.append(Literal::usize_unsuffixed(counter)); + } else { + tokens.extend(quote!(#expr)); + } + }, + } + } +} |
