Skip to Content
Beginning Rust: Get Started with Rust 2021 Edition
book

Beginning Rust: Get Started with Rust 2021 Edition

by Carlo Milanesi
January 2022
Beginner content levelBeginner
424 pages
8h 8m
English
Apress
Content preview from Beginning Rust: Get Started with Rust 2021 Edition
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
C. MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-7208-4_8

8. Using Heterogeneous Data Structures

Carlo Milanesi1  
(1)
Bergamo, Italy
 
In this chapter you will learn how to define and use other composite types:
  • Tuples

  • Structs

  • Tuple-structs

They are useful to group objects of different types.

At the end of the chapter, you’ll see some code style conventions.

The Tuples

Arrays and vectors can contain several items, yet such items must all be of the same type. If you wish to store in a single object several subobjects of different types, you can do it in this way:
let data = (10000000, 183.19, 'Q');
let copy_of_data = data;
print!("{}, {}, {}",
    data.0, copy_of_data.1, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust for Absolute Beginners: Learn Rust in 4 Hours

Rust for Absolute Beginners: Learn Rust in 4 Hours

Ajay R. Warrier
Programming with Rust

Programming with Rust

Donis Marshall
Rust Web Programming

Rust Web Programming

Maxwell Flitton

Publisher Resources

ISBN: 9781484272084Purchase LinkPublisher Website