Primitives

In Kotlin there are few commonly used primitive types:

NameBitsType
Byte8Integer
Int32Integer
Long64Integer
Float32Floating Point
Double64Floating Point
Char16UTF-16 Character
BooleanN/ABoolean

In Kotlin the Integer types are signed but there unsigned versions, i.e UByte.

Rust uses a prefix followed by the bit size to create a number type (e.g. i32 meaning a 32 bit signed integer), these are the prefixes:

CharacterType
iSigned Integer
uUnsigned Integer
fFloating Point

Floating points are 32 and 64 bit only but integers can be 8, 16, 32, 64, and 128 bits; there are also two architecture dependent sizes: isize and usize these are whatever the pointer size is for the CPU (for most new computers and phones that is 64 bits). As an example the equivalent to a Kotlin Int is i32 and a Double is f64.

usize is important as it's the primary number type: it's used in array, list and string formatting indexing and lengths/sizes of objects.

Suffixes for literals exist in Rust like in Kotlin but rather being for some types, suffixes exist for all primitives and they are the name of type, e.g. 3_i32 or 10.3f32, the suffixes are only necessary if the compiler can not infer the type or if you want to specify it; also floating point numbers can be written without the 0, e.g. 1.

Booleans are the same in both languages except it's bool instead of Boolean.

Characters are different though, char in Rust is 4 bytes and can represent any Unicode scalar value. If you need to do text manipulation and need to handle any character outside of ASCII you will probably need to use these crates:

NameDescription
unicode-segmentationUsed to iterate over grapheme clusters
unicode-normalizationConverts char + modifier into single character, this is vital if you need to compare Unicode strings

See also the Strings chapter for more information about how unicode is handled in Rust.