- 1. Rust
- 2. Self Introduction
- 2.1. Who am I?
- 2.2. Who are you?
- 3. Introduction to Rust
- 3.1. Why Rust?
- 3.2. Why Rust - Performance
- 3.3. What is written in Rust?
- 3.4. Why Rust - Reliability
- 3.5. Why Rust - Productivity
- 3.6. Major features of Rust
- 3.7. Rust Jobs
- 3.8. Memory allocation
- 3.9. Rust Books
- 3.10. Crates (3rd party libraries)
- 3.11. Rust exercises with feedback
- 3.12. Podcast, newsleter
- 3.13. Other Rust learning resources
- 3.14. Rust in other languages
- 3.15. Articles about Rust
- 3.16. Rust community
- 3.17. Demo None handling
- 3.18. Demo Option to handle None
- 3.19. Demo None handling with Option
- 3.20. Error handling
- 3.21. Demo error handling with Result
- 3.22. Demo error handling with Result and question mark
- 3.23. Error handling
- 4. Hello World
- 4.1. Install Rust
- 4.2. Editor and IDE
- 4.3. Hello World
- 4.4. Hello World with Cargo
- 4.5. Cargo build
- 4.6. Run in release mode
- 4.7. Use of macros with parentheses, square brackets, or curly braces
- 4.8. Rust and comments
- 4.9. Rust - Hello Foo
- 4.10. Interpolation
- 4.11. Printing a variable
- 4.12. Printing a variable fixed
- 4.13. Debugging print
- 4.14. Rust and print
- 4.15. Exercise: Hello World
- 5. Variables
- 5.1. Variables are immutable
- 5.2. Number in a mutable variable
- 5.3. Literal strings in variables are immutable
- 5.4. Literal string in a mutable variable can be replaced
- 5.5. A really mutable string
- 5.6. A literal string cannot be changed
- 5.7. Cannot change the type of a variable
- 5.8. Redeclare immutable variable - Shadowing
- 5.9. Redeclare immutable variable and change type - Shadowing
- 6. Convert string to number
- 6.1. Convert string to (integer) number - parse, turbofish
- 6.2. Convert string to number that ends with newline
- 6.3. Convert string to number after removing whitespaces
- 6.4. Convert string to float
- 7. Command line arguments - ARGS intro
- 7.1. Command line arguments - args
- 7.2. Exercise: Rectangle ARGS
- 7.3. Exercise: Circle ARGS
- 7.4. Exercise: basic math operations
- 7.5. Solution: Rectangle ARGS
- 7.6. Solution: Circle ARGS
- 7.7. Solution: basic math operations
- 8. Development tools
- 8.1. Code formatting
- 8.2. Clippy
- 8.3. Extreme Clippy
- 8.4. Cargo audit
- 8.5. Cargo watch
- 8.6. Pre-commit hook
- 8.7. Continuous Integration
- 9. Use libraries
- 9.1. Using the Standard library
- 9.2. Using a single value from the Standard library
- 9.3. Use (import) a name higher up in the hierarchy
- 9.4. Using a library with an alias
- 9.5. TODO: Crate library and use local library
- 10. Rust types
- 10.1. Rust Types
- 10.2. Rust infers the type of variables
- 10.3. Showing type
- 10.4. Print type of variable
- 11. Numbers
- 11.1. Rust numerical types
- 11.2. Numerical operations on integers
- 11.3. Divide integers and get float
- 11.4. Rust type mismatch in numerical operation
- 11.5. Increment integers - augmented assignment
- 11.6. unfit in i8 - compile time
- 11.7. unfit in i8 - run time - overflow
- 11.8. How to find code that might overflow / underflow?
- 11.9. Handle overflow and underflow - saturating
- 11.10. Handle overflow and underflow - checked
- 11.11. Handle overflow and underflow - overflowing
- 11.12. Handle overflow and underflow - carrying
- 11.13. Handle overflow and underflow - strict
- 11.14. Compare integers
- 11.15. Compare integers in and if-statement
- 11.16. Exponent - power
- 11.17. Exponent protecting against overflow - checked_pow, saturating_pow
- 11.18. Square root (sqrt)
- 11.19. Square root of integer numbers
- 11.20. Floating point imprecision
- 11.21. Compare floating point numbers
- 11.22. rounding float
- 11.23. Compare floating point numbers by rounding
- 11.24. Approximately compare floating point numbers
- 11.25. NaN - Not a Number
- 11.26. Infinite floating point numbers
- 11.27. Complex numbers
- 11.28. Functions and test adding numbers
- 11.29. Exercise: Rectangle ARGS with protection
- 11.30. Exercise: Rectangle add tests
- 11.31. Exercise: Circle add tests
- 11.32. Solution: Rectangle ARGS with protection
- 12. Constants
- 12.1. Rust constants
- 12.2. Constant shadowing
- 13. Characters
- 13.1. Single character
- 14. Random
- 14.1. Using 3rd party libraries
- 14.2. Random module
- 15. STDIN
- 15.1. Rust - read input from STDIN
- 15.2. Rust - read STDIN - remove trailing newline (trim, chomp)
- 15.3. Rust - flush STDOUT - read STDIN
- 15.4. Get number from STDIN
- 15.5. Get number from STDIN - same variable
- 15.6. Get number (i32) in using a function
- 15.7. Exercise: STDIN rectangle
- 15.8. Exercise: STDIN circle
- 15.9. Exercise: STDIN calculator
- 15.10. Solution STDIN rectangle
- 15.11. Solution: STDIN calculator
- 16. Loops in Rust
- 16.1. Three types of loops in Rust
- 16.2. While loop in Rust
- 16.3. Rust: loop with break
- 16.4. break returns value from loop
- 16.5. for loop in Rust
- 17. Conditional operation and boolean values in Rust
- 17.1. Conditional: if
- 17.2. Conditional: if - else
- 17.3. Conditional: else - if
- 17.4. Avoid the comparison chain using match
- 17.5. Rust: boolean values true and false
- 17.6. Assign result of conditional to variable
- 17.7. Rust: other types don't have true/false values
- 17.8. Toggle
- 17.9. if-else returns a value
- 17.10. Conditional (Ternary) operator
- 17.11. match
- 17.12. match all the numbers of an integer type
- 17.13. match all the numbers of a float type
- 17.14. match with conditions
- 17.15. Exercise: one-dimensional space-fight
- 17.16. Solution: one-dimensional space-fight
- 18. Arrays in Rust
- 18.1. Arrays in Rust
- 18.2. Rust array of numbers, length of array
- 18.3. Array of strings - access element by index
- 18.4. Array of structs
- 18.5. Array iterate on elements
- 18.6. Rust array iterate over idices
- 18.7. Rust array iterate indices and elements with enumerate
- 18.8. Rust arrays are not mutable
- 18.9. Make the Rust array mutable
- 18.10. Creating an array with the same value
- 18.11. Exercise: Count digits
- 18.12. Solution: Count digits
- 19. Option
- 19.1. The Option enum
- 19.2. Create Option
- 19.3. Checked rectangle
- 19.4. Get language function returning Option
- 20. Strings in Rust
- 20.1. Create a String
- 20.2. Create empty string and grow it using push and push_str
- 20.3. Length of string
- 20.4. Capacity of string
- 20.5. Strings and memory allocation
- 20.6. Rust - string ends with
- 20.7. Rust - string starts with
- 20.8. To lower, to upper case
- 20.9. Accessing characters in a string
- 20.10. Rust - string slices
- 20.11. Rust - string characters
- 20.12. Iterate over the characters of a string
- 20.13. Rust - reverse string
- 20.14. Concatenation str with str
- 20.15. Concatenation String with String
- 20.16. Concatenation String with String (clone)
- 20.17. Concatenation String with str
- 20.18. Concatenate strings using format!
- 20.19. concat
- 20.20. Split string
- 20.21. Split string on whitespace
- 20.22. Split on newlines - use lines
- 20.23. Append to string with push_str
- 20.24. Create String from literal string using to_string
- 20.25. Str and String equality
- 20.26. String notes
- 20.27. String replace all
- 20.28. String replace limited times
- 20.29. String replace range
- 20.30. Function to combine two strings
- 20.31. Ownership and strings
- 20.32. Slice and change string
- 20.33. Compare strings
- 20.34. Is one string in another string - contains?
- 20.35. Embed double quotes in string
- 20.36. Remove leading and trailing whitespace
- 20.37. Remove extra whitespace from string
- 20.38. String is alphabetic or alphanumeric
- 20.39. Compare memory address (pointer)
- 20.40. Exercise: Count digits from string
- 20.41. Exercise: concatenate strings
- 20.42. Exercise: is it a palindrome?
- 20.43. Exercise: is it an anagram?
- 20.44. Exercise: Get nth double character
- 20.45. Exercise: get first word
- 20.46. Solution: Count digits from string
- 21. Command line arguments - ARGS
- 21.1. Command line arguments - print all args
- 21.2. Command line program with a single file parameter
- 21.3. Exercise: calucaltor args
- 21.4. Solution: calucaltor args
- 21.5. Default value on the command line
- 21.6. Default path - return PathBuf
- 22. Tuples in Rust
- 22.1. Rust tuple - fixed-sizes, mixed, ordered collection
- 22.2. Define the types in the tuple
- 22.3. Change tuple (mutable)
- 22.4. Create tuple with types, but without values
- 22.5. Destructuring tuple
- 22.6. The empty tuple is called the unit
- 22.7. One element tuple
- 22.8. Enumerate over vector uses tuples
- 22.9. Return multiple values from a function
- 23. struct
- 23.1. Create simple struct
- 23.2. Change attributes of a mutable struct
- 23.3. Implement a method for a struct
- 23.4. Struct method to modify fields
- 23.5. Struct inheritance
- 23.6. Struct composition: Circle
- 23.7. Struct composition: Line
- 23.8. Struct with vector of structs - Polygon
- 23.9. Printing struct fails
- 23.10. Print struct - implement Display
- 23.11. Debug struct - implement Debug
- 23.12. Derive Debug for struct
- 23.13. Struct with vector and optional value
- 23.14. Printing and debug-printing simple struct
- 23.15. Use a tuple as a struct to represent color
- 23.16. Add method to tuple-based struct
- 23.17. Struct with method
- 23.18. Structs and circural references
- 23.19. new method with default values for struct
- 23.20. The new method has no special feature
- 23.21. Default values
- 23.22. Empty string and zero as default values
- 23.23. Derived Default values
- 23.24. Default for composite struct
- 23.25. Compare structs for Equality
- 23.26. Compare structs for Equality - manual implementation
- 23.27. Compare structs for partial equality - PartialEq
- 23.28. Compare structs for ordering (sorting) - Ord
- 23.29. Compare structs for partial ordering (sorting) - PartialOrd
- 23.30. Manually implement ordering
- 23.31. Copy attributes from struct instance
- 23.32. Drop - destructor
- 23.33. Exercise - struct for contact info
- 23.34. Solution - struct for contact info
- 23.35. Read from a file and return a struct
- 23.36. Converting between types: The From and Into traits
- 23.37. From and Into for String and &str
- 23.38. Implementing the From trait for 2D and 3D point structs
- 23.39. Other: Struct and type alias - Polygon
- 23.40. Other: Struct duplicate
- 23.41. Other: Multiple referene to a struct
- 23.42. Other: Print struct (Point)
- 23.43. Other: Debug struct (Point)
- 24. Vectors in Rust
- 24.1. Fixed vector of numbers
- 24.2. Iterate over elements of vector using for-loop
- 24.3. Mutable vector of numbers, append (push) values
- 24.4. Mutable empty vector for numbers (push)
- 24.5. Mutable empty vector for strings
- 24.6. Mutable empty vector with type definition
- 24.7. Mutable vector of strings
- 24.8. Remove the last element using pop, reduce capacity
- 24.9. Stack and the capacity of a vector
- 24.10. Extend vectors of numbers (combining two vectors)
- 24.11. Extend vector of Strings (combining two vectors)
- 24.12. Append vector of Strings (moving over elements)
- 24.13. Split string into iterator
- 24.14. Split string into vector
- 24.15. Sort vector of numbers
- 24.16. Sort vector of strings using sorting condition
- 24.17. Exercise: Median
- 24.18. Exercise: ROT13
- 24.19. Solution: Median
- 24.20. Solution: ROT13
- 24.21. Convert vector of chars to String
- 24.22. Vector of tuples
- 24.23. Vector of structs
- 24.24. Vector of structs - change value
- 24.25. Join elements of vector into a string
- 24.26. Join vector of integers
- 24.27. Maximum value of a vector
- 24.28. Longest or shortest string in a vector
- 24.29. Change vector of numbers using map
- 24.30. Update values in vector of structs using map
- 24.31. map is lazy
- 24.32. map is lazy that can cause problems
- 24.33. filter numbers
- 24.34. filter numbers iter into
- 24.35. filter numbers by named function
- 24.36. filter string
- 24.37. Two references to the same vector
- 24.38. Filter vector of structs (cloning)
- 24.39. Convert vector of structs to vector of references
- 24.40. Filter vector of structs without copy
- 24.41. Combine filter and map into filter_map
- 24.42. Accessing the last element of a vector
- 24.43. Insert element in vector
- 24.44. Vector with optional values - None or out of range?
- 24.45. Vector with optional values
- 24.46. Vector length and capacity
- 24.47. References to numbers
- 24.48. Queue
- 24.49. Iterate over both index and value of a vector (enumerate)
- 24.50. Create vector of strings from array of str using from_iter
- 24.51. Memory allocation of vector of numbers
- 24.52. Memory allocation of vector of strings
- 24.53. Exercise: Count words using two vectors
- 24.54. Solution: Count words using two vectors
- 25. HashMap in Rust
- 25.1. What is a HashMap?
- 25.2. Create empty HashMap, insert key-value pairs
- 25.3. Create immutable hash with data
- 25.4. Check if hash contains key (key exists)
- 25.5. Get value from hash
- 25.6. Iterate over keys of a hash
- 25.7. Iterate over key-value pairs in a Hash
- 25.8. Rust hash update value
- 25.9. Rust update values in a hash - count words
- 25.10. Remove element from hash
- 25.11. Accessing values
- 25.12. Split string create hash
- 25.13. Create hash from key-value pairs after split
- 25.14. Read key-value pairs from file
- 25.15. Sort vector of hashes
- 25.16. Mapping structs based on more than one key
- 25.17. Mapping structs based on more than one key from a vector
- 25.18. Create hash from vector of tuple pairs
- 25.19. Hash of vectors in Rust
- 25.20. Add items to a hash of vectors using a function
- 25.21. Integers as keys of a HashMap
- 25.22. Tuples as keys of a HashMap
- 25.23. Structs as keys of a HashMap
- 25.24. Merge HashMaps (extend)
- 25.25. Merge two HashMaps adding the values
- 25.26. Merge two HashMaps adding the values implemented as a function
- 25.27. Merge two HashMaps adding the values in a function
- 25.28. Convert HashMap to vector of tuples and sort by key or by value
- 25.29. Other: Add method to HashMap that sums the values
- 26. Enums
- 26.1. Why enums
- 26.2. Enum to represent exit status
- 26.3. Enum to represent exit code
- 26.4. Enumeration of the 7 days of the week
- 26.5. Enumeration with non-exhaustive patterns
- 26.6. Enumeration and manual comparision
- 26.7. Enumeration and order
- 26.8. Enumeration colors - functions and String
- 26.9. Enumeration colors - functions and str
- 26.10. Enumeration colors - with method
- 26.11. Enumeration colors - with constructor
- 26.12. Enumerate without PartialEq using match
- 26.13. Struct using enum
- 26.14. Exercise: enum for programming languages
- 26.15. Solution: enum for programming languages
- 26.16. The Result enum
- 26.17. Iterate over the variants of an enum
- 27. Files
- 27.1. Rust - write to file
- 27.2. Rust - read content of a file as a string
- 27.3. Rust - read file line-by-line
- 27.4. Rust - read file line-by-line with row number (enumerate)
- 27.5. Rust - counter
- 27.6. Rust list content of directory
- 27.7. Rust list directory content recursively (tree)
- 27.8. Makedir
- 27.9. Makedirs
- 27.10. Get the temporary directory
- 27.11. Create temporary directory
- 27.12. Current working directory
- 27.13. Change directory
- 27.14. Append to file
- 27.15. Show size of file
- 27.16. du - disk usage
- 27.17. Error handling in file operations
- 27.18. Exercise count digits in file
- 27.19. Exercise - wc (word count)
- 27.20. Exercise - simple grep
- 27.21. Exercise - du (disk usage)
- 27.22. Solution: count digits in file
- 28. Path
- 28.1. Return vector of Path or PathBuf
- 28.2. Convert the PathBuf to String to compare
- 28.3. get file extension
- 28.4. file extension
- 28.5. parent directory
- 28.6. directory ancestors (parent directories)
- 28.7. directory ancestor (n level)
- 28.8. join pathes
- 28.9. basename (file_name)
- 28.10. Relative and absolute path
- 28.11. List content of a directory - listdir
- 28.12. List dir recursively
- 29. Functions
- 29.1. Rust main function
- 29.2. Rust hello world function
- 29.3. Rust function with parameter (&str)
- 29.4. Rust functions return the unit by default
- 29.5. Rust function return value (integer i32)
- 29.6. Return the last expression (no return)
- 29.7. Return a string
- 29.8. Rust recursive functions: factorial
- 29.9. Rust recursive functions: Fibonacci
- 29.10. Make function argument mutable inside the function
- 29.11. Cannot decalre the same function twice
- 29.12. Pass by reference to change external variable - Increment in a function
- 29.13. Count digits using functions
- 29.14. Function returning multiple values
- 29.15. Function accepting multiple types (e.g. any type of numbers)
- 29.16. Function that can accept any number (any integer or any float)
- 29.17. Exercise rectangle functions
- 29.18. Exercise: is prime?
- 29.19. Scoped functions
- 30. Variable ownership in Rust
- 30.1. Stack and Heap
- 30.2. Integers are copies
- 30.3. Passing integers to functions and returning integer
- 30.4. Mutable integers are copies
- 30.5. Immutable integers are copies
- 30.6. Pass integer to function return changed value
- 30.7. Pass mutable reference of integer to function
- 30.8. Literal string
- 30.9. Literal string in mutable variable
- 30.10. Passing literal string to function
- 30.11. Mutable string in immutable variable
- 30.12. Mutable string
- 30.13. Move strings
- 30.14. Move mutable string
- 30.15. Rust clone a String
- 30.16. Rust ownership - borrow String
- 30.17. Pass ownership of String to function
- 30.18. Borrow String when passing to a function
- 30.19. Borrow &str when passing String to a function
- 30.20. Rust function to change string
- 30.21. Rust function to change integer (i32)
- 30.22. Lifetime annotation
- 30.23. Change vector of structs
- 30.24. Try to return &str from function
- 30.25. Exercise: concatenate file content
- 30.26. Pass vector to function
- 31. Date and Time
- 31.1. Measure elapsed time
- 31.2. Duration
- 31.3. Instant sleep Duration
- 31.4. Handle time (using the time crate)
- 32. Modules
- 32.1. Function in the main.rs file
- 32.2. Module defined in the main.rs file
- 32.3. Module in other file
- 32.4. Modules and enums
- 32.5. Modules and structs
- 33. Crates
- 33.1. Create a crate
- 34. Sets
- 34.1. HashSet
- 34.2. Basic Set operations in Rust
- 34.3. Union and bitor
- 34.4. Difference
- 35. Lifetime
- 35.1. Lifetime elision rules
- 35.2. Function receiving and returning one reference
- 35.3. Function receiving two and returning one reference
- 35.4. Exercise: longest string
- 35.5. Exercise: lifetime
- 36. Iterators
- 36.1. Iterate over vector of numbers
- 36.2. Alternatively, we could create an iterator using the iter method
- 36.3. Count number of elements of an iterator
- 36.4. Iterator: all the elements
- 36.5. Iteration moves values
- 36.6. Iterator that restarts
- 36.7. Circular Iterator that restarts
- 36.8. Create a simple iterator to count up to a number
- 36.9. Create a simple iterator to count boundless
- 36.10. Iterate over files in current directory
- 36.11. Iterate over files in current directory calling next
- 36.12. Iterator to walk directory tree
- 36.13. Mutable iterator
- 36.14. Take the first N elements of an iterator
- 36.15. Skip the first N elements of an iterator
- 36.16. Skip and take from an iterator
- 36.17. Counting the number of iterations - count vs collect-len
- 36.18. Exercise: Iterator for the Fibonacci series
- 36.19. Solution: Iterator for the Fibonacci series
- 36.20. Iter strings
- 36.21. Non-circular iterators
- 37. Advanced Functions
- 37.1. Pass function as argument - hello world
- 37.2. Pass function with parameter as an argument
- 37.3. Dispatch table - Calculator
- 37.4. Dispatch table - Calculator
- 37.5. Generic functions to add numbers
- 37.6. Generic functions to add numbers using where clause
- 37.7. Exercise: generic function
- 37.8. Exercise: call the add function for two points
- 37.9. Exercise: Implement function to repeate a string
- 37.10. Solution: Implement function to repeate a string
- 37.11. Solution: call the add function for two points
- 38. DateTime with Chrono
- 38.1. Chrono now
- 38.2. Elapsed time
- 38.3. Date and time arithmetic
- 38.4. Compare chrono dates
- 38.5. Format DateTime
- 38.6. Parse string to datetime
- 39. Testing
- 39.1. Testing a library crate
- 39.2. Test coverage report with tarpaulin
- 39.3. Test a function in a crate
- 39.4. Show STDOUT and STDERR during testing
- 39.5. Testing with temporary directory passed as an environment variable (test in a single thread RUST_TEST_THREADS)
- 39.6. Testing with temorary directory passed in a thread-local variable
- 39.7. Testing crates
- 39.8. Parametrization of tests
- 39.9. Rust testing setup and teardown fixtures
- 40. TOML
- 40.1. Reading a TOML file
- 40.2. Parsing TOML values
- 41. Execute and run external commands
- 41.1. The external program we'll run
- 41.2. Run external programs
- 41.3. Run external program combining parameters
- 41.4. Run a command provided as a string
- 41.5. Run external command in another directory