-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 i32
rather than usize
as "default integer" in library template
#13939
Conversation
cb0e1b8
to
8ad3510
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable. I am more curious on how you found this and why you think knowing the default integer type is important for new Rust users. Mind sharing a bit?
I found this by creating a new library with Cargo and seeing that the example code was unnecessarily using I wouldn't exactly say it's important to new Rust users, but I wouldn't set a bad example by using |
I think 64-bits is large enough to hold most numbers you use in programming. Larger sizes (e.g. 128 or 256) have more niche use cases and smaller sizes are mostly an optimization (or for fitting an external specification). There's little reason to needlessly risk overflow. I think unsigned is better because many languages don't have a separate type for signed and unsigned. So it serves to teach you about them with a nice error message if you try to use a negative. |
I don't particularly care about the exact integer type used here, |
Agree with Chris that BTW, the template was added in #10706, and somebody also needs to update the book like rust-lang/book#3533 after merge. |
`usize` was renamed from `uint` in order to convey that it's not the "default integer type". Guide new users to use integers with specific bit width instead of `usize`.
8ad3510
to
a29742a
Compare
Changed to |
The template @bors r+ |
☀️ Test successful - checks-actions |
Update cargo 7 commits in 84dc5dc11a9007a08f27170454da6097265e510e..a8d72c675ee52dd57f0d8f2bae6655913c15b2fb 2024-05-20 18:57:08 +0000 to 2024-05-24 03:34:17 +0000 - Improve error description when deserializing partial field struct (rust-lang/cargo#13956) - fix: remove symlink dir on Windows (rust-lang/cargo#13910) - Fix wrong type of rustc-flags in documentation (rust-lang/cargo#13957) - Add more high level traces (rust-lang/cargo#13951) - upgrade gix from 0.62 to 0.63 (rust-lang/cargo#13948) - Use `i32` rather than `usize` as "default integer" in library template (rust-lang/cargo#13939) - fetch specific commits even if the github fast path fails (rust-lang/cargo#13946) r? ghost
Update cargo 7 commits in 84dc5dc11a9007a08f27170454da6097265e510e..a8d72c675ee52dd57f0d8f2bae6655913c15b2fb 2024-05-20 18:57:08 +0000 to 2024-05-24 03:34:17 +0000 - Improve error description when deserializing partial field struct (rust-lang/cargo#13956) - fix: remove symlink dir on Windows (rust-lang/cargo#13910) - Fix wrong type of rustc-flags in documentation (rust-lang/cargo#13957) - Add more high level traces (rust-lang/cargo#13951) - upgrade gix from 0.62 to 0.63 (rust-lang/cargo#13948) - Use `i32` rather than `usize` as "default integer" in library template (rust-lang/cargo#13939) - fetch specific commits even if the github fast path fails (rust-lang/cargo#13946) r? ghost
Update cargo 7 commits in 84dc5dc11a9007a08f27170454da6097265e510e..a8d72c675ee52dd57f0d8f2bae6655913c15b2fb 2024-05-20 18:57:08 +0000 to 2024-05-24 03:34:17 +0000 - Improve error description when deserializing partial field struct (rust-lang/cargo#13956) - fix: remove symlink dir on Windows (rust-lang/cargo#13910) - Fix wrong type of rustc-flags in documentation (rust-lang/cargo#13957) - Add more high level traces (rust-lang/cargo#13951) - upgrade gix from 0.62 to 0.63 (rust-lang/cargo#13948) - Use `i32` rather than `usize` as "default integer" in library template (rust-lang/cargo#13939) - fetch specific commits even if the github fast path fails (rust-lang/cargo#13946) r? ghost
Update cargo 7 commits in 84dc5dc11a9007a08f27170454da6097265e510e..a8d72c675ee52dd57f0d8f2bae6655913c15b2fb 2024-05-20 18:57:08 +0000 to 2024-05-24 03:34:17 +0000 - Improve error description when deserializing partial field struct (rust-lang/cargo#13956) - fix: remove symlink dir on Windows (rust-lang/cargo#13910) - Fix wrong type of rustc-flags in documentation (rust-lang/cargo#13957) - Add more high level traces (rust-lang/cargo#13951) - upgrade gix from 0.62 to 0.63 (rust-lang/cargo#13948) - Use `i32` rather than `usize` as "default integer" in library template (rust-lang/cargo#13939) - fetch specific commits even if the github fast path fails (rust-lang/cargo#13946) r? ghost
Update cargo 7 commits in 84dc5dc11a9007a08f27170454da6097265e510e..a8d72c675ee52dd57f0d8f2bae6655913c15b2fb 2024-05-20 18:57:08 +0000 to 2024-05-24 03:34:17 +0000 - Improve error description when deserializing partial field struct (rust-lang/cargo#13956) - fix: remove symlink dir on Windows (rust-lang/cargo#13910) - Fix wrong type of rustc-flags in documentation (rust-lang/cargo#13957) - Add more high level traces (rust-lang/cargo#13951) - upgrade gix from 0.62 to 0.63 (rust-lang/cargo#13948) - Use `i32` rather than `usize` as "default integer" in library template (rust-lang/cargo#13939) - fetch specific commits even if the github fast path fails (rust-lang/cargo#13946) r? ghost
Update cargo 7 commits in 84dc5dc11a9007a08f27170454da6097265e510e..a8d72c675ee52dd57f0d8f2bae6655913c15b2fb 2024-05-20 18:57:08 +0000 to 2024-05-24 03:34:17 +0000 - Improve error description when deserializing partial field struct (rust-lang/cargo#13956) - fix: remove symlink dir on Windows (rust-lang/cargo#13910) - Fix wrong type of rustc-flags in documentation (rust-lang/cargo#13957) - Add more high level traces (rust-lang/cargo#13951) - upgrade gix from 0.62 to 0.63 (rust-lang/cargo#13948) - Use `i32` rather than `usize` as "default integer" in library template (rust-lang/cargo#13939) - fetch specific commits even if the github fast path fails (rust-lang/cargo#13946) r? ghost
usize
was renamed fromuint
in order to convey that it's not the "default integer type". Guide new users to usei32
instead ofusize
.