Code coverage Definition from Wikipedia:
In computer science, test coverage is a measure (in percent) of the degree to which the source code of a program is executed when a particular test suite is run.
Types:
Function coverage – has each function (or subroutine) in the program been called? Statement coverage – has each statement in the program been executed? Edge coverage – has every edge in the control-flow graph been executed?
I started to discover Tokio framework.
https://tokio.rs/tokio/tutorial
You can find all official tutorial code at here.
What is Tokio ultimately Asynchronous Rust code does not run on its own, so you must choose a runtime to execute it. Tokio is an asynchronous runtime for the Rust programming language. Handson tutorial with Redis-clone We’ll run a clone of Redis server. While running the redis server, your prompt will be blocked.
For someone who doesn’t know about Redis, it is a key-value store server, and you need to follow a redis protocol on TCP/IP.
Since v1.51, const generic feature was officially released.
static and const https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/const-and-static.html
static
Rust provides a ‘global variable’ sort of facility in static items. They’re similar to constants, but static items aren’t inlined upon use. This means that there is only one instance for each value, and it’s at a fixed location in memory.
const
Constants live for the entire lifetime of a program. More specifically, constants in Rust have no fixed address in memory.
I continued learning Yew after [this post]({{< ref “rust/yew_tutorial_1.md” >}}).
Important warning As of Feb. 12 2022, I’ve followed/referred the “Next” version of the Yew documentation (not only v0.19) because there are lots of changes.
And I found this statement:
You are currently reading about function components - the recommended way to write components when starting with Yew.
But we have to note that there is a more advanced, but less recommended way to write them - Struct components
Before Yew tutorial I want to try with wasm-pack, but after several tries, I realized that it was a bad try. And most parts of the official document uses Trunk, so I was back to Trunk.
Please refer to my post about Trunk.
Versions Cargo: 1.65 Yew: 0.19 Set up Rust environment for Yew rustup target add wasm32-unknown-unknown cargo install trunk My summary on Yew tutorial page I followed the official “Video page” tutorial.
Try Trunk before Yew tutorial Just follow the simplest official tutorial To understand how Trunk behaves.
I’ve simply followed the official getting started.
Set up:
cargo install trunk cargo new trunk-tutorial cd trunk-tutorial Keep the default Hello world code in src/main.rs.
Create index.html:
<html> <head> <link data-trunk rel="scss" href="index.scss"/> </head> </html> Create empty index.scss, and bild:
trunk build Feb 03 18:59:17.553 INFO 📦 starting build Feb 03 18:59:17.555 INFO spawning asset pipelines Feb 03 18:59:17.
https://rust-unofficial.github.io/patterns/patterns/creational/builder.html
TL;DR Construct an object with calls to a builder helper.
Explain with Rust example: step by step I guess this Pasta example is a bad example… need to be improved
Suppose you define a new struct (I use &str because it is just a snippet, but in real code, you should use String in this case):
struct Pasta<'a> { name: &'a str, tomato: bool, garlic: bool, special_order: &'a str } You can create/initialize an object like below:
I followed this YouTube video to learn “Type-Driven API Design”.
This note was created during review so that I could extract/summarize knowledge I didn’t know before.
Define your custom trait for all types In this video, the author want to implement progess function for a type which is an associated type Item of iterator. By using impl<T> MyTrait for T, you can implement the trait for all types in its scope.
I just followed Rust Design Pattern - Strategy (aka Policy).
Simple explanation Make code abstract as possible.
… given an algorithm solving a particular problem, we define only the skeleton of the algorithm at an abstract level, and we separate the specific algorithm’s implementation into different parts.
The stragety pattern are used frequently with dependency inversion (it is also related with high level modules).
Example Code use std::collections::HashMap; type Data = HashMap<String, u32>; trait Formatter { fn format(&self, data: &Data, buf: &mut String); } struct Report; impl Report { fn generate<T: Formatter>(g: T, s: &mut String) { let mut data = HashMap::new(); data.
What’s this page? As of Dec. 2021, I work as a DevOps engineer, but I like to solve problems with codes (front, back, whatever. it depends on the purposes.) Thesedays, my motivation about learning Rust surged enough. This page is my memo while I’ve learned with Rust official document so that I can easily remind/refer to the key feafures. Most part of this post consist of quotes from the document, but I also leave my opinions (could be wrong.