Skip to content

Latest commit

 

History

History
312 lines (171 loc) · 5.97 KB

LEARNING_RUST.md

File metadata and controls

312 lines (171 loc) · 5.97 KB

LEARNING RUST

Install Rust on MacOS, Ubuntu

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

  • Selected 'default installation' or modify options if required.
rustc --version
    rustc 1.49.0

How to update: rustup update

VS Code

Rust Extension Pack

Readings

Books available


Abhishek Chanda - Network Programming with Rust - 2018

  • score: (8 overall)
  • async part present but outdated
  • many real-world examples in detail
  • protocols covered
  • almost half of the book is dedicated to Rust basics

Rust best libraries

PRODUCTION clippy A tool that analyzes your code and makes kind of peer review reporting non-ideomatic constructs.

CLI

clap https://clap.rs/ https://github.com/clap-rs/clap

Serialization

serde https://serde.rs/

  • Meta-programming (can simplify code) build_script syn quote

HTTP clients

reqwest https://docs.rs/reqwest/

LOGGING

slog https://github.com/slog-rs/slog

log - a simpler, standard Rust logger https://docs.rs/log

DATA PROCESSING

itertools https://github.com/bluss/rust-itertools

rayon

  • give it data and it will know how to split it into independent chunks and work all your CPU cores.

NETWORKING

hyper: a fast HTTP implementation written in and for Rust https://hyper.rs/ https://github.com/hyperium/hyper

warp - build on top of hyper https://github.com/seanmonstar/warp

https://github.com/rousan/rust-web-frameworks-benchmark

DATABASES sqlx

Building fast concurrent DB https://www.youtube.com/watch?v=s19G6n0UjsM

TEMPLATE RENDERING

Jinja syntax in Rust: https://github.com/djc/askama

  • Tera: slower but does not need to re-compile for template changes

MEMORY POOLS https://github.com/sebastiencs/shared-arena

USING C AND GO https://docs.rs/libloading/0.5.0/libloading/

FLUTTER-RUST FFI https://github.com/brickpop/flutter-rust-ffi

BENCHMARKING https://github.com/sebastiencs/shared-arena/blob/master/benches/mempool.rs

CURATED LIST OF RUST PROJECTS BY CATEGORIES

https://crates.io/crates/awesome-rust

Cool projects to take into account

A safe, extensible ORM and Query Builder for Rust https://github.com/diesel-rs/diesel

Actix - super fast WEB and WebSocket server https://github.com/actix/actix-web

Basics

Cargo

Cargo is the Rust build tool and package manager.

cargo --version

Create a new project

cargo new r01_hello_world

Compile and run

cargo run

Networking

Cool frameworks

https://github.com/tokio-rs/tokio https://tokio.rs/tokio/tutorial

Async/await - for beginners

Memory allocation

Guide to porting C and C++ to Rust https://locka99.gitbooks.io/a-guide-to-porting-c-to-rust/content/features_of_rust/memory_allocation.html

Testing

https://doc.rust-lang.org/book/ch11-02-running-tests.html

UNIT TESTS

  • run unit tests for the library: cargo test --lib
  • run unit tests for specified binary crate: cargo test --bin single_file_exe
  • run all tests: cargo run
  • run only tests that contain certain name: cargo test certain_name
  • run only tests annotated with #ignore: cargo test -- --ignored

INTEGRATION TESTS

  • should be located in the project's tests directory

  • no need to create module 'test' or annotate with #[cfg(test)]

  • run with cargo test

  • run specified file with cargo test --test integration_test_file

  • each .rs file inside tests directory is compiled as separate binary target

  • in order to create multi-file integration tests, same principle as for creating multi-file modules applies, e.g.: create test_mylib_common\mod.rs and then place other .rs files into test_mylib_common.

TESTING BINARY CRATES

  • With this layout, it is impossible to create integration tests for any binary crate, so the option is to put as much code as possible into the library. Also, unit tests for binary creates are possible.

Compiling RUST for iOS

See CROSS_COMPILE projects

Internationalization

List of available crates: https://lib.rs/internationalization

https://www.projectfluent.org https://docs.rs/fluent https://lib.rs/crates/fluent https://github.com/projectfluent/fluent-rs https://habr.com/ru/post/448944/

+++ Higher-level template renderer: https://github.com/xampprocky/fluent-templates