Literals

Integer Literals

Integer literals may use decimal, hexadecimal 0x, binary 0b, or octal 0o bases.

42         // decimal
0xFF       // hexadecimal
0o77       // octal
0b10101010 // binary

There are suffixes i8, i16, i32, i64, i128, i256, i512, u8, u16, u32, u64, u128, u256, u512 to specify integer types.

-16i8   // int8
-16i16  // int16
-16i32  // int32
-16i64  // int64
-16i128 // int128
-16i256 // int256
-16i512 // int512
255u8   // uint8
255u16  // uint16
255u32  // uint32
255u64  // uint64
255u128 // uint128
255u256 // uint256
255u512 // uint512
255  // int positive
-255 // int negative
255i // int
255u // uint

Prefixes and suffixes can be combined in literals.

0b10001111i32 // int32 in binary format
0o70500u64    // uint64 in octal format
0xFFu8        // uint8 in hexadecimal format

Floating-Point Literals

3.1415      // float
3.1415f32   // float32
3.1415f64   // float64
1.0e9       // float scientific format
2.51381e-3

Boolean Literals

true
false

Character Literals

A character literal contains exactly one character (or one escape sequence) enclosed in single quotes. Its default type is char:

'A'
'∀'
'🍏'
'🍉'
'😁'
'\n'
'\\'
'a'    // char
c8'b'  // char8
c16'c' // char16
c32'd' // char32

String Literals

String literals are slices of type Slice<char8> enclosed in double quotes. Standard escape sequences are supported:

"Hello, World!"
"Line one\nLine two"
"Tab\there"
"Quote: \""
"Backslash: \\"
EscapeMeaning
\nNewline
\tHorizontal tab
\rCarriage return
\0Null byte
\\Backslash
\'Single quote
\"Double quote
\u{XXXX}Unicode code point