Rust

Rust - Getting Started (May. 2021. updating continuously)

What’s this page? As of Jan. 2021, I work as a DevOps (or infrastructure) engineer, but I like to solve problems with codes (front, back, whatever. it depends on the purposes.) For a year, my motivation abour learning Rust surges enough. This page is a memo while I’ve learned with Rust official document so that I can easily reminde the key feafures of Rust. Most part of this post consist of quotes from the document, but I also leave my opinions (could be wrong.

Basic sort algorithms in Rust

Disclamer The implementations in this post has a lot of room to improvement. As of Apr. 2021, they are more like code monkey’s code :( Reverse a string fn main() { let s1 = String::from("Please reverse me with spaces!日本語.한국어"); println!("Original string: {}",s1); let mut s2 = String::from(""); for c in s1.chars().rev() { s2.push(c); } println!("Reversed: {}",s2); } In Rust, both String and a string slice &str are UTF-8 encoded.

Rust Serverless

Getting started I followed the link. In this page, the author wrote details and it’s very educational. To remind the procedure, I left memo. I really appreciate you, Chuma Umenze :) Hello world code cargo new rust_lambda Cargo.toml: [package] // --- snip --- autobins = false [dependencies] lambda_runtime = "0.2.1" serde = { version = "^1.0", features = ["derive"] } [[bin]] name = "bootstrap" path = "src/main.rs" src/main.rs: use lambda_runtime::{error::HandlerError, lambda, Context}; use serde::{Deserialize, Serialize}; use std::error::Error; #[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] struct LambdaRequest { full_name: String, message: Option<String>, } #[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] struct LambdaResponse { lambda_request: LambdaRequest, } fn main() -> Result<(), Box<dyn Error>> { lambda!

WASM by Rust - Tutorial

Tutorial The URL I followed. https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm Pre-requirement You should install npm beforehand. To compile wasm-pack, apt install -y build-essential and install gcc. In case of Ubuntu, apt install -y libssl-dev pkg-config. Download wasm-pack To build the package, we need an additional tool, wasm-pack. This helps compile the code to WebAssembly, as well as produce the right packaging for npm. $ cargo install wasm-pack $ cargo new --lib hello-wasm $ cd hello-wasm Write codes src/lib.

Install Rust in macOS

Install Rust in macOS As of November, 2020. https://www.rust-lang.org/learn/get-started WSL In my environment (Windows Subsystem Linux), I could install as follows. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >1 echo "export PATH=$HOME/.cargo/bin:$PATH" >> ~/.bashrc Linux CentOS 8 in GCP. Basically same, but just for a memo. curl -sSf https://sh.rustup.rs | sh When memory allocation failed, try to set up RUSTUP_UMPACK_RAM.

Network tools in Rust

Motivation Learning Rust, I want to use Rust code as much as possible every day. I use Python in my daily work, and most of the scripts are for WEB (HTTP) or TCP communications. (This is another topic, but I’m a little sad most young people understand a software engineer as a web developer.) Therefore, I tried to using Rust web library. HTTP request client as of Mar. 2020 There are a lot of libraries, http, reqwest, and hyper…