O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4 - Types

Rust has a primitive string slice type, &str, and a heap-allocated and growable String type. These types guarantee Unicode safety. Bytestrings need to be used for I/O, and the type for that is simply [u8].

Arrays are fixed in size in Rust. The type for them is [T; n], where T is the type of things contained and n is the size of the array. Slices are pointers to any existing sequence and the type for that is &[T].

Traits are used to declare functionality. For example, the Into trait defines conversions between types. It can be implemented for arbitrary types.

Rust has generic types. The syntax for generic types is of the form <T>. This type can be declared in enums and structs, and then referred to in the enum or struct body. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required