Integer Types in Rust

Share this video with your friends

Send Tweet

This lesson talks about Integer types in Rust and that there are unsigned and signed integers.

It also explains how every the type names are composed of "u" and "i", for unsigned and signed respectively, followed by their with in bits. So u8 is an unsigned integer that can store values up to 8 bits (0 - 255).

J. Matthew
J. Matthew
~ 5 years ago

Several "dumb" questions:

  1. Why i instead of s for signed integers?

2a) 2^8 = 256, not 255, but the upper limit for u8 is given as 255; is that because 0 is also included, making 256 values total? (Ditto on the other types' upper bounds.)

2b) So should the comment really say 0 to 2^8-1, like the signed examples do? (And so on for the other unsigned comments.)

  1. What would be a practical application of a usize or an isize given that their capacity changes depending on the system?
Pascal Precht
Pascal Precht(instructor)
~ 5 years ago

Hi!

  1. I fear I can't answer that one. I think i makes most sense as it probably stands for integer.

2a) That is correct!

2b) I think if it you at it this way, your argument would be valid :D Sorry for the confusion.

  1. I guess this really depends on the case... Using isize or usize will give you always the biggest space on the underlying architecture. I guess there could be cases where, on a 64bit system, i/u32 would be too little, so using i/usize is a more flexible option.