dtolnay / quote

Rust quasi-quoting
Apache License 2.0
1.32k stars 90 forks source link

ToTokens for NonZero integers? #268

Closed greyblake closed 11 months ago

greyblake commented 11 months ago

Hi, thank you for the crate and your work, which powers a lot of library developers :heart:


Request

Is there any chance to implement ToTokens for NonZero integers? (::core::num::NonZeroU8, etc...)

If you're fine with the idea, I could open a PR. It may not be a plane decision, how NonZero integer should be converted into tokens

Variant A (with a runtime penalty):
::core::num::NonZeroU8::new(123).unwrap()
Variant B (with unsafe):
unsafe { ::core::num::NonZeroU8::new_unchecked(123) }

Context

In nutype I'd like to add support for NonZero integers. With my current implementation the effort would be relatively low if NonZero integers implemented ToTokens?

dtolnay commented 11 months ago

I think I would prefer not to build this into this crate. Hopefully there's a different way you could handle these in nutype.

greyblake commented 11 months ago

@dtolnay All cool. Thanks for the quick reply.