- Awesome Rust
- Dual licensing
- Procedural macros workshop
- Building distributed GraphQL backend using Rust and Apollo Federation
- On Generics and Associated Types
- Allowed and denied lints
- Building a runtime reflection system for Rust 1/3: dyn Class
- Building a runtime reflection system for Rust 2/3: dyn Attribute
- Building a runtime reflection system for Rust 2/3: dyn Method
- Closures in Rust: Capture by Immutable Borrow, by Mutable Borrow, by Move, by Unique Immutable Borrow
- Recursive iterators in Rust
- Rust Traits and Trait Objects
- Rust Language Cheat Sheet
- Programming idioms - Go vs Rust
- rust-learning - bunch of links to blog posts, articles, videos, etc for learning Rust
- Rosetta Code
- Rust Programming Techniques
- From Go to Rust - JSON and YAML
- Procedural Macros
- Generic
impl
blocks are kinda like macros - Hello Hyper!
- Making Great Docs with Rustdoc
- Slice Patterns
- Rust for the Polyglot Programmer
- Allocating Less: Really Thin Rust Cloud Apps
- A better cargo-readme
- Publishing to crates.io
- Safe pin projections through view types
- Format strings in Rust 1.58
- Building a static site generator in 100 lines of Rust
- Building a crawler in Rust: Implementing the crawler
- Building a crawler in Rust: Scraping and Parsing HTML
- Learn Rust Programming Course – Interactive Rust Language Tutorial on Replit
- David Pedersen
- Jon Gjengset
- Thomas Holloway
- Practical Programming with Dr. Xu - wgpu graphics programming
- Microsoft Beginner's Series to Rust
- The Rust Programming Language
- Rust Cookbook
- Engineering Rust Web Applications
- Zero To Production In Rust
- Rust Design Patterns
- The Little Book of Rust Books
- Learn Rust by writing Entirely Too Many Linked Lists
- Rust API Guidelines
- Asynchronous Programming in Rust
- Rust by Example
- The Little Book of Rust Macros
- Command Line Applications in Rust
- Rain's Rust CLI recommendations
- Effective Rust
- Secure Rust Guidelines
- Rust Fuzz Book
- Error Handling in Rust
- Rust for professionals
- The Rust Performance Book
- How I Built a Cross-Platform Desktop Application with Svelte, Redis, and Rust
- Tauri - Build smaller, faster, and more secure desktop applications with a web frontend
- Tauri with Standard Svelte or SvelteKit
- Creating a GTK/Glade based GUI for a Rust application
- SixtyFPS - toolkit to efficiently develop fluid graphical user interfaces for any display
- Speedrunning GUI development in Rust
- 3 Things to Try When You Can't Make a Trait Object
- Tour of Rust's Standard Library Traits
- Fn - used for closures
- FnMut - used for closures
- FnOnce - used for closures
- In order that read, write and some other methods to appear, appropriate trait has to be imported (i.e. std::io::Read)
- Forms of syntax when used as type:
&dyn Trait
&Trait
Box<Trait>
Box<dyn Trait>
- The Rust Standard Library
- Image - basic image processing functions and methods for converting to and from various image formats
- clap - Command Line Argument Parser
- kadabra - tool that makes data sharing between terminal windows easy
- mdBook - utility to create modern online books from Markdown files
- Yew - modern Rust framework for creating multi-threaded front-end web apps with WebAssembly
- nom - parser combinators library written in Rust.
- libp2p - protocols, specifications and libraries for peer-to-peer network applications
- SQLx - async SQL crate featuring compile-time checked queries
- rulex - new, portable, regular expression language
- Tokio - runtime for writing reliable, asynchronous and slim applications
- Rayon - data-parallelism library
- Crossbeam - set of tools for concurrent programming
- Concurrency in modern programming languages: Rust 1/2
- Concurrency in modern programming languages: Rust 2/2
- Actors with Tokio
- for_each_concurrent
- A practical guide to async in Rust
- Multithreading in Rust
- Creating a chat server with async Rust and Tokio
- smol - small and fast async runtime
- A Rusty Go at Channels
- Thread pool / Worker pool
- From Go to Rust - Unit Testing
- From Go To Rust - Advanced Testing
- Test Cases in Rust are simple to write
- cargo-nextest -next generation test runner for Rust projects
- cargo-fuzz - command line helpers for fuzzing
- Kani Rust Verifier - bit-precise model checker (similar as fuzzing)
- Nextest - faster test runner with JUnit serializer
assert_eq!(res.status(), 200);
- How to create small Docker images for Rust
- distroless
- Fast + Small Docker Image Builds (Alpine, compile against musl)
- Writing dockerfile in rust project
- cargo-chef - cache dependencies speed up your Docker builds
- Faster builds combining sccache and BuildKit
- cachepot - shared compilation cache
- cargo watch - watches over project source for changes and recompiles
cargo watch -q -c -w src/ -w run
- Writing a Kubernetes CRD Controller
- Evolution of kube
- kubert - Kubernetes runtime helpers
- Roperator - easily write Kubernetes Operators
- tide example app - fully fledged backend application built with Rust and tide including CRUD operations, authentication, routing, pagination, and more
- Validating JSON input in Rust web services
- Building Powerful GraphQL Servers with Rust
- rweb - yet another web server framework
- hRPC - simple RPC system for user-facing APIs
- Poem Framework -fully featured web framework based on Tokio with OpenAPI specification generation
- warp - super-easy, composable, web server framework
- axum - web application framework that focuses on ergonomics and modularity
- Askama - template rendering engine based on Jinja
- Using Askama with axum
- Example of rust-embed files with axum
- maud - compile-time HTML templates
- Salvo - powerful and simplest web server framework
- reqwest-middleware - crate implementing a wrapper around reqwest to allow for client middleware chains
- JSON to Serde
- Rustup - installer for the systems programming language Rust
- Rust Search Browser Extension
- cargo-outdated - cargo subcommand for displaying when Rust dependencies are out of date
- cargo-audit - audit Cargo.lock files for crates with security vulnerabilities
- cargo-pants - cargo subcommand to check vulnerabilities found in dependencies
- cargo-crev - cryptographically verifiable code review system
- cargo-udeps - find unused dependencies
- cargo-readme - generate README.md from doc comments
- Rust and the hidden cargo clippy
- Automatic Flamegraphs for Benchmarks in Rust
- Criterion.rs - statistics-driven micro-benchmarking tool
- Achieving warp speed with Rust
- The Rust Performance Book
fn notify(item: impl Summary) -> String {}
fn notify<T: Summary>(item: T) -> String {}
fn notify<T> Summary(item: T) -> String
where T: Summary {}
fn is_first(data: Test) -> bool {
match data {
Test::FIRST => true,
_ => false,
}
}
fn is_first(data: Test) -> bool {
matches!(data, Test::FIRST)
}
When a function is not implemented, use unimplemented! macro inside the body.
Useful if you are prototyping and are just looking to have your code typecheck.
- Wrapping errors in Rust
- Ergonomic error handling with Rust
- A Beginner's Guide to Handling Errors in Rust
- How to Tackle Error in Rust Programming
- The simplest guide to error handling in Rust
- Beginner-Intermediate Rust error handling
#[derive(Fail)]
pub enum MyError {
Server(u8)
User(String)
Connection,
}
#[derive(Debug)]
enum MyError {
Lock,
}
impl<T> From<PoisonError<T>> for MyError {
fn from(_: PoisonError<T>) -> MyError {
MyError::Lock
}
}
fn main() -> Result<(), MyError> {}
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
let f = match File::open("file.txt") {
Ok(file) => do_something_with(file),
Err(e) => match e.kind() {
ErrorKind::NotFound => match File::create("file.txt") {
Ok(file2) => do_something_with(file2),
Err(e2) => panic!("{:?}", e2)
},
_ => panic!("something weird happened")
}
}
fn read_file() => Result<String, io::Error> {
let mut f = File::open("file.txt") {
Ok(file) => do_something_with(file),
Err(e) => return Err(e), // here we need return
}
let mut s = String::new();
match f.read_to_string(&mut s) {
Ok(_) => Ok(s), // return not needed here because match is the last expression in the function
Err(e) => Err(e), // return not needed here because match is the last expression in the function
}
}
fn read_file() => Result<String, io::Error> {
let mut f = File::open("file.txt")?;
let mut s = String::new();
f.read_to_string(&mut s)?;
Ok(s)
}
fn read_file() => Result<String, io::Error> {
let mut s = String::new();
File::open("file.txt")?.read_to_string(&mut s)?;
Ok(s)
}
fn main() => Result<(), Box<dyn Error>> {
let f File::open("file.txt")?;
Ok(s)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {}
use thiserror::Error;
#[derive(Error, Debug)]
pub enum DataStoreError {
#[error("data store disconnected")]
Disconnect(#[from] io::Error),
#[error("the data for key `{0}` is not available")]
Redaction(String),
#[error("invalid header (expected {expected:?}, found {found:?})")]
InvalidHeader {
expected: String,
found: String,
},
#[error("unknown data store error")]
Unknown,
}
- Iteration patterns for Result & Option
- Returning Rust Iterators
- Creating an Iterator in Rust
- Rust iterators tips and tricks
use std::iter::once;
struct Color {
r: u8,
g: u8,
b: u8,
}
impl Color {
fn iter(&self) -> impl Iterator<Item = u8> {
once(self.r).chain(once(self.g)).chain(once(self.b))
}
}
fn main() {
let color = Color {
r: 100,
g: 0,
b: 150,
};
for v in color.iter() {
println!("{}", v);
}
}
Box::new(Foo { data: 32 }) as Box<dyn Any>
cargo doc --no-deps --open
#![warn(missing_debug_implementations, rust_2018_idioms, missing_docs)]
rustc -W help
rustup update stable
fn print_power_action(state: PowerState) {
use PowerState::*;
match state {
Off,
Sleep,
Reboot,
Shutdown,
Hibernate,
}
}
let ref mut remainder = self.remainder?; // self.remainder: Option<&str>
is equal to
let remainder = self.remainder.as_must()?;
extern crate openssl;
extern crate postgres;
use postgres::{Connection, TlsMode};
use openssl::ssl::{SslConnectorBuilder, SslMethod, SslVerifyMode};
use openssl::x509;
fn main() {
let mut connector = SslConnectorBuilder::new(SslMethod::tls()).unwrap();
connector.set_ca_file("root.crt").unwrap();
connector
.set_certificate_file("postgresql.crt", x509::X509_FILETYPE_PEM)
.unwrap();
connector
.set_private_key_file("postgresql.key", x509::X509_FILETYPE_PEM)
.unwrap();
// openssl::ssl::SslVerfifyMode constant in not defined yet in openssl 0.9.23 which is rust-postgres dependency
// disable certificate hostname check
let mode = SslVerifyMode::empty();
connector.set_verify(mode);
let negotiator = postgres::tls::openssl::OpenSsl::from(connector.build());
let conn = Connection::connect(
"postgres://postgres@localhost:5432",
TlsMode::Require(&negotiator),
).unwrap();
let res = conn.query("SELECT 1+1 as foo", &[]).unwrap();
for row in &res {
let foo: i32 = row.get(0);
println!("{}", foo);
}
}
apt-get install cmake libfontconfig1-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev
[dependencies]
winit = { git = "https://github.com/project/crate", branch = "branch-name" }
[patch.crates-io]
winit = { git = "https://github.com/project/crate", branch = "branch-name" }