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

Document the maximum and minimum values of each number type #66099

Closed
yoshuawuyts opened this issue Nov 5, 2019 · 11 comments · Fixed by #66221
Closed

Document the maximum and minimum values of each number type #66099

yoshuawuyts opened this issue Nov 5, 2019 · 11 comments · Fixed by #66221
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue.

Comments

@yoshuawuyts
Copy link
Member

Values such as u8::MAX are nice when coding because they capture the max allowed value of a number without needing to hard-code it yourself, or apply tricks to compute it.

However when trying to decide which number type to use, it'd be nice to have a plain-text definition of the number types in the documentation. Because even clicking through to the source does not yield the information you're looking for.

I think this would be a small change that could make getting used to Rust's number types significantly easier. Thanks!

Screenshots

Screenshot_2019-11-05 std i8 MAX - Rust
Rust's MAX docs don't contain much information currently. It seems like it wouldn't be too bad to add a bit more to it.

@Centril Centril added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. labels Nov 5, 2019
@Manishearth
Copy link
Member

We should also do this for some of the other constants that are floating around (like EPSILON)

If we do this for usize we should make sure to mention both values

Some of these are macro generated, so this could be a bit tricky to get right!

@Mark-Simulacrum
Copy link
Member

I suspect the macro bit is actually maybe leading to the problem here -- I seem to recall something going by recently about constants getting pretty-printed into metadata, which I assumed meant we were rendering their values in rustdoc. Maybe the macros are leading to that not happening?

That won't help for usize/isize I guess but I think it would be good to look into this theory for the other types at least a bit

@Manishearth
Copy link
Member

I don't think we ever show constant values in rustdoc. Would be nice to, but there are a bunch of tricky bits.

@varkor
Copy link
Member

varkor commented Nov 5, 2019

I don't think we ever show constant values in rustdoc.

Unstably, we show constant values for const generics, so we need to handle const value printing in rustdoc anyway. It's not perfect yet, but it works in most simple situations. We should be able to use the same infrastructure to print const values.

@Otolock
Copy link

Otolock commented Nov 6, 2019

I would be interested in adding this for at least for the integer types listed in the book. What is the preferred way that this look like on the documentation?

Something like:

The largest value that can be represented by this integer type: -128

Or

The largest value that can be represented by this integer type.

-128

Or would it be similar to the documentation for the primitive type i8's min_value() function, where an assert_equal is used to state the expected value?

@Otolock
Copy link

Otolock commented Nov 7, 2019

cc @steveklabnik

@steveklabnik
Copy link
Member

IMHO, the former is simpler and straightforward, seems good to me.

@Dylan-DPC-zz
Copy link

@rustbot claim @ohadravid

@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2019

Error: Parsing assign command in comment failed: ...tbot claim|error: expected end of command at >| @ohadravi...

Please let @rust-lang/release know if you're having trouble with this bot.

@Dylan-DPC-zz
Copy link

@rustbot assign @ohadravid

@segfaultsourcery
Copy link

I wouldn't mind taking this on, if it's not already taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants