Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Rust

You're reading from   Learning Rust A comprehensive guide to writing Rust applications

Arrow left icon
Product type Paperback
Published in Nov 2017
Publisher Packt
ISBN-13 9781785884306
Length 308 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Vesa Kaihlavirta Vesa Kaihlavirta
Author Profile Icon Vesa Kaihlavirta
Vesa Kaihlavirta
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Title Page
Preface
1. Introducing and Installing Rust FREE CHAPTER 2. Variables 3. Input and Output 4. Conditions, Recursion, and Loops 5. Remember, Remember 6. Creating Your Own Rust Applications 7. Matching and Structures 8. The Rust Application Lifetime 9. Introducing Generics, Impl, and Traits 10. Creating Your Own Crate 11. Concurrency in Rust 12. Now It's Your Turn! 13. The Standard Library 14. Foreign Function Interfaces

What exactly is a crate?


As with all languages, Rust can use external libraries that, we've established are called crates. But what are they?

If we think about a crate, we think either of something we use to hold lots of other things. Software developers like to keep their code clean and if they know what they're doing, they tend to keep their libraries fairly specialized. These specialisms within a crate are known as modules.

Note

A crate is a container with one or more modules within it.

Looking at modules

To show how crates are put together, we are going to create one. In this case, it will be a simple math crate.

Before we consider this, let's consider something we all know: a car. We will consider the car a crate, as everything to do with the car is held within it.

To start, let's think about the main parts of the car: the engine, fuel, interior, wheels and movement, and electrics.

There are more but, for now, we will ignore them. Let's represent this as a block diagram to make the relationship...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images