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 Programming By Example

You're reading from   Rust Programming By Example Enter the world of Rust by building engaging, concurrent, reactive, and robust applications

Arrow left icon
Product type Paperback
Published in Jan 2018
Publisher Packt
ISBN-13 9781788390637
Length 454 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
 Gomez Gomez
Author Profile Icon Gomez
Gomez
Antoni Boucher Antoni Boucher
Author Profile Icon Antoni Boucher
Antoni Boucher
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Basics of Rust FREE CHAPTER 2. Starting with SDL 3. Events and Basic Game Mechanisms 4. Adding All Game Mechanisms 5. Creating a Music Player 6. Implementing the Engine of the Music Player 7. Music Player in a More Rusty Way with Relm 8. Understanding FTP 9. Implementing an Asynchronous FTP Server 10. Implementing Asynchronous File Transfer 11. Rust Best Practices 1. Other Books You May Enjoy Index

Opening MP3 files


Let's finish this chapter by adding the ability to open MP3 files and show their metadata in the playlist widget we just created.

First of all, we'll remove this line:

cover.set_from_file("cover.jpg");

This is because the image will be set from the data of the MP3 files we play.

We'll use a new crate, so add this line in the [dependencies] section of your Cargo.toml:

gtk-sys = "^0.5.0"

Also, add the following line to your main.rs:

extern crate gtk_sys;

The *-sys crates of the gtk-rs ecosystem are low-level crates, the ones that directly bind to the GTK+ C library. Since they're very low-level and require the use of unsafe code, wrappers have been made; these are crates without the -sys suffix, such as gtk and gdk.

Reference-counting pointer

We'll also change some code before we continue. Since we'll want to share our Playlist widget with different parts of our code, including some event handlers, we need a way of sharing a reference that will last long enough (remember the issue...

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