❮ Index
❯
TOC: Rust programming
- Self Introduction
- 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
- Demo None handling with Option
- Demo error handling with Result
- Demo error handling with Result and question mark
- Hello World
- Install Rust
- Editor and IDE
- Hello World
- Hello World with Cargo
- Cargo build
- Run in release mode
- Use of macros with parentheses, square brackets, or curly braces
- Rust and comments
- Rust - Hello Foo
- Interpolation
- Printing a string
- 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 literal string cannot be changed
- Really mutable string
- Cannot change variable type
- Redeclare immutable variable - Shadowing
- Redeclare immutable variable and change type - Shadowing
- Convert string to number
- Command line arguments - ARGS demo
- Development tools
- Use libraries
- Rust types
- 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
- Characters
- Random
- 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
- 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
- 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
- Tuples in Rust
- 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
- 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 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
- Enum
- 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
- 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
- Error handling in Rust
- Runtime error (panic) noticed during compilation.
- Divide by zero panick in function
- Return error on failure
- Divide by zero runtime panic
- Divide by zero return error
- factorial function, runtime panic
- factorial create panic
- Out of bound for vectors
- Out of bound for arrays
- Open files
- Error handling on the command line
- main returning Result - Set exit code
- Error in internal function
- Date and Time
- DateTime with Chrono
- CSV
- Handlebars
- liquid templating
- What is a template engine?
- Install
- Liquid use-cases
- Liquid Hello World
- Liquid Hello World with variable
- Liquid Hello World read template from file
- Liquid Hello World embed template file
- Liquid flow control: if - else
- Liquid flow control: else if written as elsif
- Liquid flow control: case/when
- Liquid passing more complex data
- Liquid for loop passing a vector or an array
- Liquid vector of tuples
- Liquid HashMap
- Liquid for loop with if conditions
- Liquid with struct
- Liquid with Option in a struct
- Liquid include
- Liquid include header and footer
- Liquid layout (include and capture)
- Liquid assign to variable in template
- Liquid filters on strings: upcase, downcase, capitalize
- Liquid filters on numbers: plus, minus
- Liquid filters: first, last
- Liquid filter reverse array
- Liquid for loop: limit, offset, reversed
- Liquid comma between every two elements (forloop.last)
- Liquid: create your own filter: reverse a string
- Liquid: create your own filter: commafy
- Liquid: length of string, size of vector
- Liquid: Embed HTML - escape HTML
- Liquid tags
- Liquid create your own tag without parameters
- Liquid create your own tag with a single parameter
- Liquid create your own tag with many values
- Liquid create your own tag accepting two numbers
- Liquid create your own tag with attribute as key=value pair
- Liquid create tag that uses scalar values passed to the render function
- Liquid create tag that uses array of values passed to the render function (latest, limit, tag)
- Liquid create include tag that overrides existing include tag
- Liquid TODO
- Modules
- Crates
- 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
- Threads in Rust
- Threads in Rust
- Available cores
- Simple thread (with fake work)
- Simple thread
- Simple thread with join
- Show that threads work in parallel
- Return value from thread
- Handle panic! in threads
- Threads polling the substhreads
- Threads with messages
- Two threads sending messages
- Testing speed improvements with threads
- Save many files (both CPU and IO intensive)
- Rust threads read-only access to shared variables
- Shared read-only variable with numeric value
- Shared read-only variable with string value
- Shared read-only variable with string value with Arc
- Pass reference of read-only vector to thread
- Pass reference of read-only vector to thread improved
- Process read-only string slices in parallel
- Filling the memory showing that Arc works
- Pass and return ownership
- Thread scope
- chdir in threads
- Environment variables in threads
- Counter in a loop in the same process and thread
- Mutex - without threads
- Lock with Mutex
- Counter with threads (shared variable) using Mutex
- Counter with threads (local counting)
- Counter with message passing
- thread-local variables
- Exercise: character counting
- Exercise: word count
- Exercise: count characters, words
- Exercise: run several functions on the same text
- Exercise: Download many files in threads
- Solution: count characters, words
- Solution: run several functions on the same text
- Threadpool
- Threaded map
- rayon
- async
- Regex
- Sets
- CLI - Command line Interface with clap
- Clap - Command Line Argument Parser
- Clap Single positional argument
- Clap Several positional arguments
- Clap Single long argument
- Clap Short arguments
- Clap accepting string, number, bool - default values
- Clap add help to each argument
- Clap show the version number from Cargo.toml
- Clap Show the description of the crates using the about command
- Clap Show the description written in the code
- Clap show generated description
- Clap validate number range
- Clap subcommands
- Clap mutually exclusive
- Clap mutually exclusive with group
- Clap example for CLI
- Clap: improving the help with value_name
- Clap: one of a fixed list of values (enumerated)
- Clap and environment variables
- Clap - set default value if other flag provided
- Clap - set default value if other argument provided
- Clap - set default value based on another flag
- Clap complete enum - name of shell
- Repeat the same argument several times
- Limit the number of values for a vector argument
- Clap: fixed list of valid values for generic type
- Clap: arbitraty function to validate argument )
- Clap: default value only if the flag was provides
- JSON
- Serde for JSON
- Read Simple JSON file manually
- Read Simple JSON file into a struct
- Read JSON file using from_reader manually
- Read JSON file using from_reader to a struct
- Read complex JSON
- JSON files - missing fields
- Read JSON handle missing fields - set defaults
- Read JSON with Optional fields
- Read JSON avoid extra fields - deny_unknown_fields
- Alias some fields in JSON (handle dash in JSON keys)
- Read JSON to Vector
- Read lists of JSON structures
- Serialize and deserialize HashMap to JSON in Rust
- JSON serialize struct
- Serialize struct and Deserialize JSON
- JSON serialize examples
- serde manipulate json (change, add)
- JSON serialize struct with date
- YAML
- TOML
- 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
- image
- http
- Logging
- Execute and run external commands
- Macros
- Declarative macros
- Examples of standard declarative macros
- todo! for and if-condition
- todo! for a match
- unimplemented
- About Declarative macros
- Hello World macro
- Macro with literal values
- Macro with parameter to say hello
- Fragment specifiers
- Macro with literal
- Macro with ident - create function
- Macro with optional parameter to say hello
- Macro with many parameters to say hello
- Macro to create a HashMap to be a counter
- Macro prt! to explore memory allocation
- Macro String::from
- Macro ok! to replace unwrap
- Macro pair! to create tuple with Some
- Optional function parameters using macros
- Debugging macros using trace_macros
- Define a function using a macro
- Error logging
- Some crates that provide macros
- HTML to string macro
- Using a helper macro vs helper function in tests
- Procedural macros
- egui
- SQLite
- SQLite crate
- SQLite in memory example with INSERT and SELECT
- SQLite in-memory COUNT
- SQLite in-memory plain placeholder (?)
- SQLite SELECT with named placeholder - bind variables
- SQLite SELECT with placeholder
- SQLite INSERT with placeholder
- SQLite Multi-Counter
- SQLite with AUTOINCREMENT
- SQLite - field with DEFAULT value
- SQLite Transaction
- SQLite transaction - bank
- SQLite - Groups and Owners (with FOREIGN KEY)
- SQLite get_autocommit function
- Binary
- Learning tasks
- Task: Setup environment
- Task: Print Hello World
- Exercise: Hello world
- Task: Get input from command line and print it
- Hello Foo
- Task: Get two numbers from the command line and do some calculations on them
- Add two numbers in main
- Set type of numbers
- get two numbers from args and add them together
- add protection to args (if , len)
- add protection to number parsing
- Exercise: rectangle, circle
- Task: Implement file-based counter
- Task: Word Count (wc)
- unsafe
- Tera
- Rocket
- Rocket - A web framework for Rust
- Rocket - Hello World
- Rocket - Hello World with separate test file
- Rocket - Hello World returning static RawHtml
- Rocket - Generated RawHtml page
- Rocket - Hello World with Tera template
- Rocket - Echo using GET
- Rocket - Echo using POST
- Rocket - Path parameters
- Rocket - Single hit-counter using a text file
- Rocket - Logging to the console
- Rocket - Logging to a file using log4rs
- Rocket - Calculator with GET (passing multiple parameters)
- Rocket - Calculator with GET (passing multiple parameters) using enum
- Rocket - In-memory counter using State
- Rocket - get, set (add), delete cookies - pending cookies
- Rocket - Multi-counter using cookies (in the client)
- Rocket - Multi-counter using secure cookies (in the client)
- Rocket - Automatic reload of the application (watch)
- Rocket - Two applications in separate files
- Rocket - Redirect to another page
- Rocket - Redirect with parameters
- Rocket - Serving static files
- Rocket - 404 page with static content
- Rocket - Access custom configuration in the routes
- Rocket - Custom configuration and injecting (overriding) values in tests
- Rocket - Request guard - FromRequest
- Rocket - Blog using request guard - FromRequest
- Rocket - Blog with FromParam - selectively accept pathes
- Rocket - Return Status (arbitrary HTTP code)
- Rocket - catch panic in the route handle
- Simple TODO list with Rocket and SurrealDB
- Use Tera filters (length)
- Create Tera filters
- Skip route by returning None
- Skip route using a guard
- Rocket Guards - experiment
- Rocket return user-id
- Rocket People and groups
- Rocket Userid in path
- SurrealDB
- What is SurrealDB
- SurrealDB in-memory database in Rust
- SurrealDB with RocksDB backend in Rust embedded client with local database storage
- Start SurrealDB in Docker
- SurrealDB connect to server
- CREATE and SELECT in Memory
- Several ways to add a record to the database
- SurrealDB CREATE SELECT in different ways
- SurrealDB in-memory with SQL demo in Rust - CREATE (INSERT), SELECT, UPDATE, DELETE
- SurrealDB experiments
- SurrealDB - REMOVE NAMESPACE
- SurrealDB - CREATE, SELECT, DELETE
- SurrealDB - Datetime with Chrono
- SurrealDB - CREATE, SELECT, UPDATE, DELETE
- SurrealDB - RSVP
- SurrealDB - toggle
- Multi-counter with embedded SurrealDB database
- Get version of SurrealDB
- Generate ID in SurrealDB
- Generate Thing in SurrealDB
- Map field to id of other table (FOREIGN KEY)
- SurrealDB Datetime
- Add column to table without a schema
- SurrealDB - Schema
- SurrealDB - define field type - try to create entry with incorrect type (int, string)
- SurrealDB - extra fields are ignored in SCHEMAFULL
- SurrealDB - missing field
- SurrealDB - add field to schema
- SurrealDB in Docker using the CLI
- SurrealDB - references and SELECT
- SurrealDB Demo
- SurrealDB columns with schema
- SurrealDB TODO
- Sea ORM
- Other
- Variable shadowing
- String formatting
- Factorial functions returning Result
- Split function into files
- Variable Scope in Rust
- Declare empty variable and assign to it later
- Declare empty variable - requires type
- SystemTime now
- Exit
- Define multiple variables
- wc
- copy vs clone
- Type alias
- Struct and type alias - Polygon
- Solution: Age limit
- Multi-counter in manually handled CSV file
- Get path to current executable
- cache dependencies with sccache
- Commafy
- Commafys
- Use statements
- Take version number from Cargo.toml
- Ansi colors
- What I learned from learning Rust
- Temperature converter
- Check slides
- Expressions vs statements
- Send email via SendGrid
- Equality of Some - values
- Fork
- sysinfo - Which Operating System are we running on?
- Operating system information with os_info
- Parse string to Rust expression using syn
- Parse HTML
- Fix URL parameter
- My little Rust runner
- Crate library and use local library
- Ordered floats
- Linked list using struct and Box
- Undirected graph
- Memory leak
- Debug assertions
- Add method to HashMap that sums the values
- Passing string to function
- Struct duplicate
- Multiple referene to a struct
- Print struct (Point)
- Debug struct (Point)
- Num traits
- map with threads with Mutex
- Accessing envrionment variables
- List environment variables
- Closures
- Reference to a number
- Out of memory
- Two leveles of modules
- Try packages
- release.toml
- thousands crate for struct with Display (commafy)
- Early return on None Option
- Pattern matching with guards on a number