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
Rust High Performance

You're reading from   Rust High Performance Learn to skyrocket the performance of your Rust applications

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788399487
Length 272 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Eguia Moraza Eguia Moraza
Author Profile Icon Eguia Moraza
Eguia Moraza
Arrow right icon
View More author details
Toc

Extra performance tips


Compile-time checks are not the only place where you can benefit from a performance enhancement at no cost. While in Chapter 1Common Performance Pitfalls, we saw the common errors people write in Rust, we left the most advanced tips and tricks for this chapter.

Using closures to avoid runtime evaluation

Sometimes, it might seem natural to write code that does not perform as fast as expected. Many times, this is due to Rust doing some extra computations at runtime. An example of an unnecessary computation that someone could write is the following:

    let opt = Some(123);
    let non_opt = opt.unwrap_or(some_complex_function());

I have intentionally made this example simply because a real example usually takes really long code. The idea behind it is valid though. When you have an Option or a Result, you have some very useful functions to allow you get the value inside or a default. There is this specific function, the unwrap_or() function, that allows you specify the...

You have been reading a chapter from
Rust High Performance
Published in: Mar 2018
Publisher: Packt
ISBN-13: 9781788399487
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 £13.99/month. Cancel anytime
Visually different images