Book Image

Rust Programming By Example

By : Guillaume Gomez, Antoni Boucher
Book Image

Rust Programming By Example

By: Guillaume Gomez, Antoni Boucher

Overview of this book

Rust is an open source, safe, concurrent, practical language created by Mozilla. It runs blazingly fast, prevents segfaults, and guarantees safety. This book gets you started with essential software development by guiding you through the different aspects of Rust programming. With this approach, you can bridge the gap between learning and implementing immediately. Beginning with an introduction to Rust, you’ll learn the basic aspects such as its syntax, data types, functions, generics, control flows, and more. After this, you’ll jump straight into building your first project, a Tetris game. Next you’ll build a graphical music player and work with fast, reliable networking software using Tokio, the scalable and productive asynchronous IO Rust library. Over the course of this book, you’ll explore various features of Rust Programming including its SDL features, event loop, File I/O, and the famous GTK+ widget toolkit. Through these projects, you’ll see how well Rust performs in terms of concurrency—including parallelism, reliability, improved performance, generics, macros, and thread safety. We’ll also cover some asynchronous and reactive programming aspects of Rust. By the end of the book, you’ll be comfortable building various real-world applications in Rust.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
3
Events and Basic Game Mechanisms
Index

Index

A

  • API tips, Rust
    • some function, explaining /  Explaining the Some function
    • Path function, using /  Using the Path function
  • application
    • improving / Improving the organization of the application
  • arrays
    • about / Arrays
    • slices / Slices
    • for loops / For loops
  • asynchronous IO
    • advantages / Advantages of asynchronous IO
    • disadvantages / Disadvantages of asynchronous IO
  • asynchronous user interface / Asynchronous user interface

B

  • binary project
    • creating / Creating the new project
  • builder pattern
    • about / Builder pattern
    • mutable borrows, playing / Playing with mutable borrows
    • moves, playing / Playing with moves
  • built-in data types
    • about / Built-in data types
    • integer types / Integer types
    • floating-point types / Floating-point types
    • Boolean type / Boolean type
    • character type / Character type
  • bytes codec
    • about / Bytes codec
    • data bytes, decoding / Decoding data bytes
    • data bytes, encoding / Encoding data bytes

C

  • cargo / Cargo and crates.io
  • Cargo.toml file / Back to our Cargo.toml file
  • child widget
    • adding / Adding child widgets
    • one-way data binding / One-way data binding
    • post-initialization of view / Post-initialization of the view
    • dialogs / Dialogs
    • methods / Other methods
  • chunks of commands
    • implementation / Implementing simple chunks of commands, Starting with basics
    • basics / Starting with basics
  • clients
    • handling / Handling clients
  • code blocks / Code blocks
  • code readability, Rust
    • big number formatting / Big number formatting
    • types, specifying / Specifying types
    • matching / Matching
  • commands
    • handling / Handling commands, Handling commands
  • commands implementation
    • about / Commands implementation
    • SYST command, implementation / Implementing the SYST command
    • USER command, implementation / Implementing the USER command
    • NOOP command, implementation / Implementing the NOOP command
    • PWD command, implementation / Implementing the PWD command
    • TYPE command, implementation / Implementing the TYPE command
    • LIST command, implementation / Implementing the LIST command, Full implementation of the LIST command
    • CWD command, implementation / Implementing the CWD command
    • CDUP command, implementation / Implementing the CDUP command
    • MKD command, implementation / Implementing the MKD command
    • RMD command, implementation / Implementing the RMD command
  • config.toml access
    • securing / Securing the config.toml access
  • configuration / Going further!, Configuration
  • containers
    • about / Containers
    • types / Types of containers
    • box container / The Box container
  • control flow
    • about / Control flow
    • condition, writing / Writing a condition
    • while loops, creating / Creating while loops
    • copy types / Copy types
    • mutable references / Mutable references
  • cover
    • displaying / Displaying the cover when playing a song
  • CPU usage
    • improving / Improving CPU usage
    • condition variable / Condition variable
  • crate
    • reference link / Cargo and crates.io
    • documenting / Documenting a crate
  • current directory
    • managing / Managing the current working directory
    • printing / Printing the current directory
    • changing / Changing the current directory
  • custom widgets
    • creating / Creating custom widgets

D

  • dependencies
    • installing / Installing the dependencies
    • installing, on Linux / Installing dependencies on Linux
    • installing, on Mac / Installing dependencies on Mac
    • installing, on Windows / Installing dependencies on Windows
  • dialogs / Dialogs
  • directories
    • creating / Creating directories
    • removing / Removing directories
  • doc blocks
    • about / About the doc blocks themselves
    • code blocks lines, hiding / Hiding code blocks lines
  • docs.rs documentation
    • about / The docs.rs documentation
    • Cargo.toml file / Back to our Cargo.toml file
  • documentation
    • about / Documentation
    • generating / Generating the documentation
    • testing / Documentation tests
    • tags / Tags
  • drawing
    • about / Drawing
    • options, playing / Playing with Options
    • solution / Solution
    • images, loading / Loading images
    • features, playing / Playing with features
    • images, playing / Playing with images

E

  • enumeration
    • about / Enumerations
    • documenting / Documenting an enumeration (or any type with public fields)
  • error handling
    • about / Handling errors
    • unwrapping / Unwrapping
    • error type / Custom error type
  • error type
    • about / Custom error type
    • error, displaying / Displaying the error
    • displaying / Displaying the error
    • composing / Composing error types
    • ? operator, revisited / The ? operator, revisited
  • event loop
    • about / Event loop
    • atomic reference counting / Atomic reference counting
    • mutual exclusion / Mutual exclusion
    • send trait / Send trait
    • sync trait / Sync trait
    • lock-free data structures / Lock-free data structures
    • Resource Acquisition Is Initialization (RAII) / RAII

F

  • file
    • handling / Handling files
    • high scores, loading / Saving/loading high scores
    • high scores, saving / Saving/loading high scores
    • iterators / Iterators
    • formatted data, reading / Reading formatted data from files
    • opening, with file dialog / Opening files with a file dialog
    • listing / Listing files
    • downloading / Downloading a file
    • uploading / Uploading files
  • fonts
    • installing, on OS X / Install on OS X
    • installing, on Linux / Install on Linux
    • system/package manager / Other system/package manager
    • loading / Loading font
  • FTP / Introduction to FTP
  • FTP codec / FTP codec
  • FTP commands
    • decoding / Decoding FTP commands
    • encoding / Encoding FTP commands
  • FTP protocol
    • about / File transfer protocol
    • chunks of commands, implementation / Implementing simple chunks of commands
    • commands implementation / Commands implementation
    • testing / Testing it
  • functions
    • creating / Creating functions
  • futures
    • using / Using futures

G

  • game map
    • interacting / Interacting with the game map
  • game mechanisms
    • about / Getting started with game mechanisms
    • rendering UI / Rendering UI
    • fonts / Playing with fonts
  • generics
    • about / Generics
    • option type / The Option type
  • gstreamer
    • used, for playback / Using gstreamer for playback
  • GTK+
    • installing, on Linux / Installing GTK+ on Linux
    • installing, on Mac / Installing GTK+ on Mac
    • installing, on Windows / Installing GTK+ on Windows

H

  • headers / Headers
  • high scores
    • loading / Saving/loading high scores, Highscores loading/overwriting
    • saving / Saving/loading high scores
    • overwriting / Highscores loading/overwriting

I

  • ID3
    • MP3 metadata / ID3— MP3 metadata
  • images
    • SDL2_image, installing on Mac / Installing SDL2_image on Mac
    • SDL2_image, installing on Linux / Installing SDL2_image on Linux
  • integration tests
    • about / Integration tests
    • teardown / Teardown
    • output, printing to stdout / Print output to stdout
  • interior mutability / Interior mutability
  • irrefutable patterns / Irrefutable patterns
  • items
    • hiding, from documentation / Hiding items from the documentation
  • iterators / Iterators

L

  • level / Score, level, lines sent, Levels and lines sent
  • lines sent / Score, level, lines sent, Levels and lines sent
  • LIST command / Back to the LIST command

M

  • macros
    • about / Macros
    • multiple pattern rules / Multiple pattern rules
    • repetitions / Repetitions
  • messages / Messages
  • methods
    • about / Methods, Other methods
    • constructors / Constructors
  • model / Model
  • model parameter / Model parameter
  • module
    • documenting / Documenting a module
  • MP3 decoder
    • implementing / Implementing an MP3 decoder
  • MP3 files
    • opening / Opening MP3 files
    • decoding / Decoding MP3 files
    • dependencies, adding / Adding dependencies
    • frame samples / Getting the frame samples
  • Multiple-Producers-Single-Consumer (MPSC) / Playing music
  • music
    • playing / Playing music, Playing music, Playing music
    • event loop / Event loop
    • mutex guard / Mutex guard
  • music player
    • using / Using the music player
  • MVC pattern / The MVC pattern

O

  • one-way data binding / One-way data binding

P

  • passive mode
    • entering / Entering passive mode
    • bytes codec / Bytes codec
  • PASV command
    • implementation / Implementing the PASV command
  • pattern matching
    • about / Pattern matching
    • irrefutable patterns / Irrefutable patterns
  • playlist
    • adding / Adding a playlist
    • MVC pattern / The MVC pattern
    • loading / Loading and saving the playlist, Loading a playlist
    • saving / Loading and saving the playlist, Saving a playlist
    • about / Playlist
    • model parameter / Model parameter
  • post-initialization of view / Post-initialization of the view
  • prerequisite
    • installing / Installing the prerequisite
    • GTK+, installing on Linux / Installing GTK+ on Linux
    • GTK+, installing on Mac / Installing GTK+ on Mac
    • GTK+, installing on Windows / Installing GTK+ on Windows
  • public items
    • warning, without documentation / Warning about public items without documentation

Q

  • quitting / Quitting

R

  • reference-counting pointer / Reference-counting pointer
  • references
    • about / References
    • clone types / Clone types
  • relm
    • used, instead of gtk-rs directly / Reasons to use relm instead of gtk-rs directly
    • state mutation / State mutation
    • asynchronous user interface / Asynchronous user interface
    • custom widgets, creating / Creating custom widgets
    • window, creating / Creating a window with relm
    • Rust nightly, installing / Installing Rust nightly
    • used, on stable Rust / Using relm on stable Rust
  • relm widget
    • adding / Adding a relm widget
    • data binding / Relm widgets data binding
  • rendering / Rendering
  • rendering initialization / Rendering initialization
  • repetitions, macros
    • optional quantifier / Optional quantifier
  • Rust
    • about / Getting to know Rust
    • installing / Installing Rust
    • Windows / Windows
    • Linux/Mac / Linux/Mac 
    • installation, testing / Test your installation
    • references / Documentation and reference
    • main function / Main function
    • variables / Variables
    • best practices / Rust best practices
    • slices / Slices
    • API tips / API tips and improvements
    • improvements / API tips and improvements
    • usage tips / Usage tips
    • code readability / Code readability
  • Rust's modules / Rust's modules
  • Rust crates / Understanding Rust crates
  • Rust nightly
    • installing / Installing Rust nightly
  • Rust project
    • setting up / Setting up your Rust project
    • cargo / Cargo and crates.io
    • crates.io / Cargo and crates.io
    • docs.rs documentation / The docs.rs documentation

S

  • score / Score, level, lines sent
  • SDL2
    • installing / Installing SDL2
    • installing, on Linux / Installing SDL2 on Linux
    • installing, on Windows / Installing SDL2 on Mac, Installing SDL2 on Windows
    • Windows, with Build / Windows with Build Script
    • Windows (MinGW) / Windows (MinGW)
    • Windows (MSVC) / Windows (MSVC)
  • SDL2_image
    • installing, on Windows / Installing SDL2_image on Windows
  • SDL events / SDL events
  • Semantic Versioning (SemVer) / Setting up your Rust project
  • server
    • about / Starting the server
    • clients, handling / Handling clients
    • commands, handling / Handling commands
    • FTP codec / FTP codec
  • slices / Slices
  • song
    • deleting / Deleting a song
    • pausing / Pausing and resuming the song
    • resuming / Pausing and resuming the song
    • progression, displaying / Showing the progression of the song
    • current time, displaying / Showing the song's current time
  • song duration
    • computing / Computing the song duration
  • stable Rust
    • relm, used / Using relm on stable Rust
  • state mutation / State mutation
  • structures
    • creating / Creating structures

T

  • tags, documentation
    • ignore / ignore
    • compile_fail / compile_fail
    • no_run / no_run
    • should_panic / should_panic
    • flags, combining / Combining flags?
  • tests
    • fuzzing / Fuzzing tests
  • tetrimino
    • about / Tetrimino
    • creating / Creating tetriminos
    • generating / Generating a tetrimino
    • rotating / Rotating a tetrimino
  • tetris / Tetris
  • Tetris
    • writing / Writing Tetris
  • tetris struct / Tetris struct
  • Tokio
    • using / Using Tokio
    • event loop / Tokio event loop
  • Tokio event loop / Starting the Tokio event loop
  • toolbar
    • creating / Creating a toolbar
    • stock item / Stock item
  • tool button events
    • adding / Adding tool button events
    • lifetime / Lifetime
    • ownership / Ownership
  • traits
    • about / Traits
    • default methods / Default methods
    • associated types / Associated types
    • rules / Rules
  • transfer type
    • setting / Setting the transfer type
  • tuples / Tuples

U

  • unit tests
    • about / Unit tests
    • backtraces / Backtraces
    • failures, testing / Testing failures
    • tests, ignoring / Ignoring tests
  • unwrapping / Unwrapping
  • usage tips, Rust
    • builder pattern / Builder pattern

V

  • view
    • about / View
    • properties / Properties
    • events / Events
    • code generation / Code generation

W

  • widget
    • about / Widget
    • model / Model
    • messages / Messages
    • view / View
    • update function / Update function
    • communicating / Communicating with the same widget
    • emit / Emit
    • method / With different widgets
    • messages, handling from relm widget / Handle messages from a relm widget
    • message, sending to relm widget / Syntax sugar to send a message to another relm widget
  • widgets
    • communicating / Communicating between widgets
  • window
    • creating / Creating a window
  • Window
    • creating / Creating your first window, Closure
    • default behavior, preventing of an event / Preventing the default behavior of an event
    • creating, with relm / Creating a window with relm