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

Use the num-traits crate directly instead of num #948

Merged
merged 2 commits into from Dec 30, 2019

Conversation

dmitmel
Copy link
Contributor

@dmitmel dmitmel commented Dec 3, 2019

I noticed that this crate uses only two features of num-traits:

  1. num::FromPrimitive - used to convert raw integers to Rust enums. Is using an external library for this really necessary?
  2. num::ToPrimitive - used to convert colors isize values to colors, replaced it with std::convert::TryFrom.
  3. num::traits::cast - used in literally only one place, so I replaced it with std::convert::TryInto.

The FromPrimitive trait is located in the num-traits crate, so by depending on it instead of all of num I managed to reduce the total number of dependencies from 25 to 18. Also I took the opportunity and upgraded it from v0.1 to v0.2.

If using num-traits for int <-> enum conversions is an overkill in your opinion, I can also open a PR to remove it from dependencies altogether.

@dmitmel dmitmel changed the title Switch to num traits Switch to num-traits Dec 3, 2019
@dmitmel dmitmel changed the title Switch to num-traits Use the num-traits crate directly instead of num Dec 3, 2019
@Cobrand
Copy link
Member

Cobrand commented Dec 30, 2019

Sorry, for some reason I didn't receive a notification for this PR... Thanks!

@Cobrand Cobrand merged commit 3f21baa into Rust-SDL2:master Dec 30, 2019
@dmitmel
Copy link
Contributor Author

dmitmel commented Dec 30, 2019

Should I remove num-traits altogether in favor of std's From?

@dmitmel dmitmel deleted the switch-to-num-traits branch December 30, 2019 16:35
@Cobrand
Copy link
Member

Cobrand commented Dec 30, 2019

It's true that the num_traits crate is used only to convert 5 enums... I think it'd be wise to remove entirely the dependency, indeed.

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

2 participants