스칼라 타입
| 타입 | 리터럴 값 | |
|---|---|---|
| 부호있는 정수 | i8, i16, i32, i64, i128, isize | -10, 0, 1_000, 123_i64 |
| 부호없는 정수 | u8, u16, u32, u64, u128, usize | 0, 123, 10_u16 |
| 부동소수 | f32, f64 | 3.14, -10.0e20, 2_f32 |
| 문자열 | &str | "foo", "two\nlines" |
| 유니코드 문자 | char | 'a', 'α', '∞' |
| 불리언 | bool | true, false |
각 타입의 크기는 다음과 같습니다:
iN,uN,fN은 모두 _N_비트 입니다.isize와usize는 포인터와 같은 크기입니다,char32 비트 입니다,bool은 8 비트 입니다.
위에 표시되지 않은 몇 가지 문법이 있습니다:
-
Raw strings allow you to create a
&strvalue with escapes disabled:r"\n" == "\\n". You can embed double-quotes by using an equal amount of#on either side of the quotes:fn main() { println!(r#"<a href="link.html">link</a>"#); println!("<a href=\"link.html\">link</a>"); } -
Byte strings allow you to create a
&[u8]value directly:fn main() { println!("{:?}", b"abc"); println!("{:?}", &[97, 98, 99]); } -
All underscores in numbers can be left out, they are for legibility only. So
1_000can be written as1000(or10_00), and123_i64can be written as123i64.