Rust Programming
$19.00
Minimum price
$29.00
Suggested price

Rust Programming

An introduction to the Rust programming language

About the Book

The books is based on the training material used for teaching Rust to both Python, C, and C++ developers.

About the Author

Gábor Szabó
Gábor Szabó

Gabor Szabo has been programming for more than 40 years in a number of languages and in various environments. He used to do DevOps before there was a name for it.

These days he usually helps companies improve their engineering practices by providing training, introducing test automation, CI, CD. Sometimes this includes building internal web sites. Gabor also loves explaining things and provides training to his clients.

He also has a number of websites. Each one using a different technology.

Gabor runs the Code Maven site and a number of its sub-site where he write about lots of different technologies such as Python, Rust, Git, Continuous Integration, etc.

Gabor has been writing Perl since 1995 and teaching it since 2000. He is the author of the Perl Maven site including the Perl Tutorial. He has taught web development with Perl Dancer many time including at Perl Conferences in Europe and USA. Gabor is the chief editor of the Perl Weekly newsletter.

Table of Contents

    • Thank you!
    • Rust Programming
    • Self Introduction
    • Who am I?
    • Who are you?
    • Introduction to Rust
    • Why Rust?
    • Why Rust - Performance
    • What is written in Rust?
    • Why Rust - Reliability
    • Why Rust - Productivity
    • Major features of Rust
    • Rust Jobs
    • Memory allocation
    • Rust Books
    • Crates (3rd party libraries)
    • Rust exercises with feedback
    • Podcast, newsleter
    • Other Rust learning resources
    • Rust in other languages
    • Articles about Rust
    • Rust community
    • Demo None handling
      • Use variable before initialization?
    • Demo Option to handle None
      • Usage
      • Some extra notes
    • Demo None handling with Option
    • Error handling
      • Exception
      • Return status code
      • Return a Result
    • Demo error handling with Result
      • Always checking the returned value?
    • Demo error handling with Result and question mark
    • Error handling
    • Hello World
    • Install Rust
    • Editor and IDE
    • Hello World in Rust!
    • Hello World in Rust with Cargo
      • Compile and run in one step
    • Cargo build
      • Release mode
    • Run in release mode
    • Use of macros with parentheses, square brackets, or curly braces
    • Rust and comments
    • Rust - Hello Foo
    • Interpolation
    • Printing a variable
    • Printing a string fixed
    • Debugging print
    • Rust and print
    • Exercise: Hello World
    • Variables
    • Variables are immutable
    • Number in a mutable variable
    • Literal strings in variables are immutable
    • Literal string in a mutable variable can be replaced
      • A little about memory
    • A really mutable string
    • A literal string cannot be changed
    • Cannot change the type of a variable
    • Redeclare immutable variable - Shadowing
    • Redeclare immutable variable and change type - Shadowing
    • Convert string to number
    • Convert string to (integer) number - parse, turbofish
    • Convert string to number that ends with newline
    • Convert string to number after removing whitespaces
    • Convert string to float
    • Command line arguments - ARGS intro
    • Command line arguments - args
    • Exercise: Rectangle ARGS
    • Exercise: Circle ARGS
    • Exercise: basic math operations
    • Solution: Rectangle ARGS
    • Solution: Circle ARGS
    • Solution: basic math operations
    • Development tools
    • Code formatting
    • Clippy
    • Extreme Clippy
    • Cargo audit
    • Cargo watch
    • Pre-commit hook
    • Continuous Integration
    • Use libraries
    • Using the Standard library
    • Using a single value from the Standard library
    • Use (import) a name higher up in the hierarchy
    • Using a library with an alias
    • TODO: Crate library and use local library
    • Rust types
    • Rust Types
    • Rust infers the type of variables
    • Showing type
    • Print type of variable
    • Numbers
    • Rust numerical types
    • Numerical operations on integers
    • Divide integers and get float
    • Rust type mismatch in numerical operation
    • Increment integers - augmented assignment
    • unfit in i8 - compile time
    • unfit in i8 - run time - overflow
    • How to find code that might overflow / underflow?
    • Handle overflow and underflow - saturating
    • Handle overflow and underflow - checked
    • Handle overflow and underflow - overflowing
    • Handle overflow and underflow - carrying
    • Handle overflow and underflow - strict
    • Compare integers
    • Compare integers in and if-statement
    • Exponent - power
    • Exponent protecting against overflow - checked_pow, saturating_pow
    • Square root (sqrt)
    • Square root of integer numbers
    • Floating point imprecision
    • Compare floating point numbers
    • rounding float
    • Compare floating point numbers by rounding
    • Approximately compare floating point numbers
    • NaN - Not a Number
    • Infinite floating point numbers
    • Complex numbers
    • Functions and test adding numbers
    • Exercise: Rectangle ARGS with protection
    • Exercise: Rectangle add tests
    • Exercise: Circle add tests
    • Solution: Rectangle ARGS with protection
    • Constants
    • Rust constants
    • Constant shadowing
    • Characters
    • Single character
    • Random
    • Using 3rd party libraries
    • Random module
    • STDIN
    • Rust - read input from STDIN
    • Rust - read STDIN - remove trailing newline (trim, chomp)
    • Rust - flush STDOUT - read STDIN
    • Get number from STDIN
    • Get number from STDIN - same variable
    • Get number (i32) in using a function
    • Exercise: STDIN rectangle
    • Exercise: STDIN circle
    • Exercise: STDIN calculator
    • Solution STDIN rectangle
    • Solution: STDIN calculator
    • Loops in Rust
    • Three types of loops in Rust
    • While loop in Rust
    • Rust: loop with break
    • break returns value from loop
    • for loop in Rust
    • Conditional operation and boolean values in Rust
    • Conditional: if
    • Conditional: if - else
    • Conditional: else - if
    • Avoid the comparison chain using match
    • Rust: boolean values true and false
    • Assign result of conditional to variable
    • Rust: other types don’t have true/false values
    • Toggle
    • if-else returns a value
    • Conditional (Ternary) operator
    • match
    • match all the numbers of an integer type
    • match all the numbers of a float type
    • match with conditions
    • Exercise: one-dimensional space-fight
    • Solution: one-dimensional space-fight
    • Arrays in Rust
    • Arrays in Rust
    • Rust array of numbers, length of array
    • Array of strings - access element by index
    • Array of structs
    • Array iterate on elements
    • Rust array iterate over idices
    • Rust array iterate indices and elements with enumerate
    • Rust arrays are not mutable
    • Make the Rust array mutable
    • Creating an array with the same value
    • Exercise: Count digits
    • Solution: Count digits
    • Option
    • The Option enum
    • Create Option
    • Checked rectangle
    • Get language function returning Option
    • Strings in Rust
    • Create a String
    • Create empty string and grow it using push and push_str
    • Length of string
    • Capacity of string
    • Strings and memory allocation
    • Rust - string ends with
    • Rust - string starts with
    • To lower, to upper case
    • Accessing characters in a string
    • Rust - string slices
    • Rust - string characters
    • Iterate over the characters of a string
    • Rust - reverse string
    • Concatenation str with str
    • Concatenation String with String
    • Concatenation String with String (clone)
    • Concatenation String with str
    • Concatenate strings using format!
    • concat
    • Split string
    • Split string on whitespace
    • Split on newlines - use lines
    • Append to string with push_str
    • Create String from literal string using to_string
    • Str and String equality
    • String notes
    • String replace all
    • String replace limited times
    • String replace range
    • Function to combine two strings
    • Ownership and strings
    • Slice and change string
    • Compare strings
    • Is one string in another string - contains?
    • Embed double quotes in string
    • Remove leading and trailing whitespace
    • Remove extra whitespace from string
    • String is alphabetic or alphanumeric
    • Compare memory address (pointer)
    • Exercise: Count digits from string
    • Exercise: concatenate strings
    • Exercise: is it a palindrome?
    • Exercise: is it an anagram?
    • Exercise: Get nth double character
    • Exercise: get first word
    • Solution: Count digits from string
    • Command line arguments - ARGS
    • Command line arguments - print all args
    • Command line program with a single file parameter
    • Exercise: calucaltor args
    • Solution: calucaltor args
    • Default value on the command line
    • Default path - return PathBuf
    • Tuples in Rust
    • Rust tuple - fixed-sizes, mixed, ordered collection
    • Define the types in the tuple
    • Change tuple (mutable)
    • Create tuple with types, but without values
    • Destructuring tuple
    • The empty tuple is called the unit
    • One element tuple
    • Enumerate over vector uses tuples
    • Return multiple values from a function
    • struct
    • Create simple struct
    • Change attributes of a mutable struct
    • Implement a method for a struct
    • Struct method to modify fields
    • Struct inheritance
    • Struct composition: Circle
    • Struct composition: Line
    • Struct with vector of structs - Polygon
    • Printing struct fails
    • Print struct - implement Display
    • Debug struct - implement Debug
    • Derive Debug for struct
    • Struct with vector and optional value
    • Printing and debug-printing simple struct
    • Use a tuple as a struct to represent color
    • Add method to tuple-based struct
    • Struct with method
    • Structs and circural references
    • new method with default values for struct
    • The new method has no special feature
    • Default values
    • Empty string and zero as default values
    • Derived Default values
    • Default for composite struct
    • Compare structs for Equality
    • Compare structs for Equality - manual implementation
    • Compare structs for partial equality - PartialEq
    • Compare structs for ordering (sorting) - Ord
    • Compare structs for partial ordering (sorting) - PartialOrd
    • Manually implement ordering
    • Copy attributes from struct instance
    • Drop - destructor
    • Exercise - struct for contact info
    • Solution - struct for contact info
    • Read from a file and return a struct
    • Converting between types: The From and Into traits
    • From and Into for String and &str
    • Implementing the From trait for 2D and 3D point structs
    • Other: Struct and type alias - Polygon
    • Other: Struct duplicate
    • Other: Multiple referene to a struct
    • Other: Print struct (Point)
    • Other: Debug struct (Point)
    • Vectors in Rust
    • Fixed vector of numbers
    • Iterate over elements of vector using for-loop
    • Mutable vector of numbers, append (push) values
    • Mutable empty vector for numbers (push)
    • Mutable empty vector for strings
    • Mutable empty vector with type definition
    • Mutable vector of strings
    • Remove the last element using pop, reduce capacity
    • Stack and the capacity of a vector
    • Extend vectors of numbers (combining two vectors)
    • Extend vector of Strings (combining two vectors)
    • Append vector of Strings (moving over elements)
    • Split string into iterator
    • Split string into vector
    • Sort vector of numbers
    • Sort vector of strings using sorting condition
    • Exercise: Median
    • Exercise: ROT13
    • Solution: Median
    • Solution: ROT13
    • Convert vector of chars to String
    • Vector of tuples
    • Vector of structs
    • Vector of structs - change value
    • Join elements of vector into a string
    • Join vector of integers
    • Maximum value of a vector
    • Longest or shortest string in a vector
    • Change vector of numbers using map
    • Update values in vector of structs using map
    • map is lazy
    • map is lazy that can cause problems
    • filter numbers
    • filter numbers iter into
    • filter numbers by named function
    • filter string
    • Two references to the same vector
    • Filter vector of structs (cloning)
    • Convert vector of structs to vector of references
    • Filter vector of structs without copy
    • Combine filter and map into filter_map
    • Accessing the last element of a vector
    • Insert element in vector
    • Vector with optional values - None or out of range?
    • Vector with optional values
    • Vector length and capacity
    • References to numbers
    • Queue
    • Iterate over both index and value of a vector (enumerate)
    • Create vector of strings from array of str using from_iter
    • Memory allocation of vector of numbers
    • Memory allocation of vector of strings
    • Exercise: Count words using two vectors
    • Solution: Count words using two vectors
    • HashMap in Rust
    • What is a HashMap?
    • Create empty HashMap, insert key-value pairs
    • Create immutable hash with data
    • Check if hash contains key (key exists)
    • Get value from hash
    • Iterate over keys of a hash
    • Iterate over key-value pairs in a Hash
    • Rust hash update value
    • Rust update values in a hash - count words
    • Remove element from hash
    • Accessing values
    • Split string create hash
    • Create hash from key-value pairs after split
    • Read key-value pairs from file
    • Sort vector of hashes
    • Mapping structs based on more than one key
    • Mapping structs based on more than one key from a vector
    • Create hash from vector of tuple pairs
    • Hash of vectors in Rust
    • Add items to a hash of vectors using a function
    • Integers as keys of a HashMap
    • Tuples as keys of a HashMap
    • Structs as keys of a HashMap
    • Merge HashMaps (extend)
    • Merge two HashMaps adding the values
    • Merge two HashMaps adding the values implemented as a function
    • Merge two HashMaps adding the values in a function
    • Convert HashMap to vector of tuples and sort by key or by value
    • Other: Add method to HashMap that sums the values
    • Enums
    • Why enums
    • Enum to represent exit status
    • Enum to represent exit code
    • Enumeration of the 7 days of the week
    • Enumeration with non-exhaustive patterns
    • Enumeration and manual comparision
    • Enumeration and order
    • Enumeration colors - functions and String
    • Enumeration colors - functions and str
    • Enumeration colors - with method
    • Enumeration colors - with constructor
    • Enumerate without PartialEq using match
    • Struct using enum
    • Exercise: enum for programming languages
    • Solution: enum for programming languages
    • The Result enum
    • Iterate over the variants of an enum
    • Files
    • Rust - write to file
    • Rust - read content of a file as a string
    • Rust - read file line-by-line
    • Rust - read file line-by-line with row number (enumerate)
    • Rust - counter
    • Rust list content of directory
    • Rust list directory content recursively (tree)
    • Makedir
    • Makedirs
    • Get the temporary directory
    • Create temporary directory
    • Current working directory
    • Change directory
    • Append to file
    • Show size of file
    • du - disk usage
    • Error handling in file operations
    • Exercise count digits in file
    • Exercise - wc (word count)
    • Exercise - simple grep
    • Exercise - du (disk usage)
    • Solution: count digits in file
    • Path
    • Return vector of Path or PathBuf
    • Convert the PathBuf to String to compare
    • get file extension
    • file extension
    • parent directory
    • directory ancestors (parent directories)
    • directory ancestor (n level)
    • join pathes
    • basename (file_name)
    • Relative and absolute path
    • List content of a directory - listdir
    • List dir recursively
    • Functions
    • Rust main function
    • Rust hello world function
    • Rust function with parameter (&str)
    • Rust functions return the unit by default
    • Rust function return value (integer i32)
    • Return the last expression (no return)
    • Return a string
    • Rust recursive functions: factorial
    • Rust recursive functions: Fibonacci
    • Make function argument mutable inside the function
    • Cannot decalre the same function twice
    • Pass by reference to change external variable - Increment in a function
    • Count digits using functions
    • Function returning multiple values
    • Function accepting multiple types (e.g. any type of numbers)
    • Function that can accept any number (any integer or any float)
    • Exercise rectangle functions
    • Exercise: is prime?
    • Scoped functions
    • Variable ownership in Rust
    • Stack and Heap
    • Integers are copies
    • Passing integers to functions and returning integer
    • Mutable integers are copies
    • Immutable integers are copies
    • Pass integer to function return changed value
    • Pass mutable reference of integer to function
    • Literal string
    • Literal string in mutable variable
    • Passing literal string to function
    • Mutable string in immutable variable
    • Mutable string
    • Move strings
    • Move mutable string
    • Rust clone a String
    • Rust ownership - borrow String
    • Pass ownership of String to function
    • Borrow String when passing to a function
    • Borrow &str when passing String to a function
    • Rust function to change string
    • Rust function to change integer (i32)
    • Lifetime annotation
    • Change vector of structs
    • Try to return &str from function
    • Exercise: concatenate file content
    • Pass vector to function
    • Date and Time
    • Measure elapsed time
    • Duration
    • Instant sleep Duration
    • Handle time (using the time crate)
    • Modules
    • Function in the main.rs file
    • Module defined in the main.rs file
    • Module in other file
    • Modules and enums
    • Modules and structs
    • Crates
    • Create a crate
    • Sets
    • HashSet
    • Basic Set operations in Rust
    • Union and bitor
    • Difference
    • Lifetime
    • Lifetime elision rules
    • Function receiving and returning one reference
    • Function receiving two and returning one reference
    • Exercise: longest string
    • Exercise: lifetime
    • Iterators
    • Iterate over vector of numbers
    • Alternatively, we could create an iterator using the iter method
    • Count number of elements of an iterator
    • Iterator: all the elements
    • Iteration moves values
    • Iterator that restarts
    • Circular Iterator that restarts
    • Create a simple iterator to count up to a number
    • Create a simple iterator to count boundless
    • Iterate over files in current directory
    • Iterate over files in current directory calling next
    • Iterator to walk directory tree
    • Mutable iterator
    • Take the first N elements of an iterator
    • Skip the first N elements of an iterator
    • Skip and take from an iterator
    • Counting the number of iterations - count vs collect-len
    • Exercise: Iterator for the Fibonacci series
    • Solution: Iterator for the Fibonacci series
    • Iter strings
    • Non-circular iterators
    • Advanced Functions
    • Pass function as argument - hello world
    • Pass function with parameter as an argument
    • Dispatch table - Calculator
    • Dispatch table - Calculator
    • Generic functions to add numbers
    • Generic functions to add numbers using where clause
    • Exercise: generic function
    • Exercise: call the add function for two points
    • Exercise: Implement function to repeate a string
    • Solution: Implement function to repeate a string
    • Solution: call the add function for two points
    • DateTime with Chrono
    • Chrono now
    • Elapsed time
    • Date and time arithmetic
    • Compare chrono dates
    • Format DateTime
    • Parse string to datetime
    • Testing
    • Testing a library crate
    • Test coverage report with tarpaulin
    • Test a function in a crate
    • Show STDOUT and STDERR during testing
    • Testing with temporary directory passed as an environment variable (test in a single thread RUST_TEST_THREADS)
    • Testing with temorary directory passed in a thread-local variable
    • Testing crates
    • Parametrization of tests
    • Rust testing setup and teardown fixtures
    • TOML
    • Reading a TOML file
    • Parsing TOML values
    • Execute and run external commands
    • The external program we’ll run
    • Run external programs
    • Run external program combining parameters
    • Run a command provided as a string
    • Run external command in another directory

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub