matsadler / magnus

Ruby bindings for Rust. Write Ruby extension gems in Rust, or call Ruby from Rust.
https://docs.rs/magnus/latest/magnus/
MIT License
682 stars 35 forks source link

Add `TryConvert` for `NonZero` types #120

Closed ankane closed 1 month ago

ankane commented 1 month ago

This PR adds support for NonZero types, which is part of std::num.

I tried using NonZero<T>, but ZeroablePrimitive is a nightly trait, so used a macro instead. It raises an ArgumentError if the value is zero, but I think a TypeError would work as well.

Edit: Switched to NonZeroI8, NonZeroI16, etc. since NonZero<T> is not available in 1.61.

matsadler commented 1 month ago

Thank you! This looks good. Could you rebase on main, that should fix the failing tests, and then I'll merge this.

ankane commented 1 month ago

Thanks @matsadler!