用小齒輪來帶動大齒輪 - 用Rust做Rust的開發工具
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7545760/bicycle.jpg)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7088226/1024px-Rust_programming_language_black_logo.svg.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7545748/neovim_log.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7545763/Gears.png)
How to learn?
By writing some side projects
Asking for
Rust Project ?!!
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7545813/RustProjects.jpg)
Asking for Rust Side project ???
What is Trait of Rust ?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7545862/go_vs_rust.png)
Trait of Rust
Trait of Rust
-
No peak, No GC (X)
-
Smooth mem usage (X)
-
Hard to find a job (O)
-
write it daily (O)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7545862/go_vs_rust.png)
Trait of Rust
Peak and periodic
Smooth and constantly
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7545862/go_vs_rust.png)
Trait of Rust
X coordinate is Date !
Lack a lot of things
but a lot of side projects
:)
How to find a Rust Side project ???
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7582773/Lovepik_com-400732126-a-chestnut.png)
For example
What's in my laptop?
Archlinux - An OS in kiss way
packer - An arch user repository manager
tig - A command line git viewer (C)
zsh - one of cool shell (c?)
qtile - a hackable tile windows manger (python)
neovim - a text editor
python - a good script language (C)
json - a data format
Redox OS
![](https://www.redox-os.org/img/redox-orbital/large.png)
Redox is a Unix-like Operating System written in Rust, aiming to bring the innovations of Rust to a modern microkernel and full set of applications.
Too hard to me
RUA
I use it, it's good and nothing need to be fixed or enhanced.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7582868/Rua.png)
Nu Shell &
![](https://raw.githubusercontent.com/starship/starship/master/media/logo.png)
![](https://raw.githubusercontent.com/nushell/nushell/main/images/nushell-autocomplete.gif)
wtftw
Window Tiling For The Win. A tiling window manager written in Rust
Neovide
![](https://raw.githubusercontent.com/Kethku/neovide/master/assets/AnimatedCursor.gif)
This is a simple graphical user interface for Neovim. Where possible there are some graphical improvements, but it should act functionally like the terminal UI.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7585022/RustPython.png)
![](https://raw.githubusercontent.com/extrawurst/gitui/master/assets/demo.gif)
![](https://raw.githubusercontent.com/extrawurst/gitui/master/assets/logo.png)
It is really cool
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7582909/DiffKey.png)
RON? what is this?
RON - Rusty Object Notation
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7583133/ron.png)
RIIR
A little bit crazy?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7583092/riir.png)
Why RIIR
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7583092/riir.png)
Efficacy &
Safe
use Rust
- Participate it
- And learn more
Still Why Rust?
System Call for Windows Server running IIS.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7589988/IIS.jpg)
Find the line with error
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7585080/server.jpg)
"fatal error" by kerolic is licensed under CC BY-NC-SA 2.0
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7585152/EthCable.jpg)
Some cable plugin & Green light for OK
Option
fn checked_division(dividend: i32, divisor: i32) -> Option<i32> {
if divisor == 0 {
None
} else {
Some(dividend / divisor)
}
}
Result
fn sqrt(x: f64) -> Result<f64, &'static str> {
if x < 0.0 {
Err("Do not sqrt the negative number")
} else {
Ok(x.sqrt())
}
}
Rust don't put wires into box and pretend clear
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7585173/WireInBox.jpg)
"DSCF2319.JPG" by em978 is licensed under CC BY-NC 2.0
Rust make every thing ordered
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7586613/CleanLines.jpg)
"6148-336-448_Server_room_cabling_nightmare" by DrJohnBullas is licensed under CC BY-NC-ND 2.0
How to deal
Option & Result
Directly Unwarp
let quotient = checked_division(a, b).unwrap()
- You 100% sure there is always a value
- use default value - the pythonic thought
let quotient = checked_division(a, b).unwrap_or_default()
- use my default value - the pythonic thought
let quotient = checked_division(a, b).unwrap_or(1)
let quotient = checked_division(a, b).expect("Message")
- You 100% sure there is always a value
Click
me !
Result to Option
let root = sqrt(x).ok()
- Change the result to option
- use default value - the pythonic thought
let root = sqrt(x).err()
let root = sqrt(x).or(sqrt(-x))
- use fail back Result
For All Conditions
match checked_division(a, b) {
Some(i) => { ... },
None => {...}
}
match sqrt(a) {
Ok(i) => { ... },
Err(e) => {...}
}
For one Condition
if let Some(r) = checked_division(a, b) {
r
}
if checked_division(a, b).is_none() {
}
if checked_division(a, b).is_some() {
}
if let Ok(r) = sqrt(a) {
r
}
if let Err(e) = sqrt(a) {
e
}
if sqrt(a).is_ok() {
}
if sqrt(a).is_err() {
}
What's the main problem when relocated?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7588662/relocate.jpg)
"IMG_3461" by Jemimus is licensed under CC BY 2.0
Where are scissors & tape ?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7588654/Tape_Sezers.jpg)
Borrow & Return
let char_list = vec!['c', 'o', 's', 'c', 'u', 'p'];
let mut sentence = char_list;
sentence.push('.');
println!("{:?}", sentence);
//println!("{:?}", char_list);
Borrow & Return
let char_list = vec!['c', 'o', 's', 'c', 'u', 'p'];
{
let mut sentence = char_list;
sentence.push('.');
println!("{:?}", sentence);
}
println!("{:?}", char_list); // not work
Is Rust Object oriented ?
impl & trait
use std::default::Default;
#[derive(Debug)]
struct Car {
gas: i32,
gas_consumption: i32
}
impl Car {
fn try_to_go(&mut self, mile: i32) -> Result<i32, &'static str> {
...
}
}
Rust is good,
help you work better
Back to topic
Nvim translation plugin
![](https://raw.githubusercontent.com/yanganto/nvim-translate/master/snapshot.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/831034/images/7594872/db_keys.png)
That is my scenario
![](https://raw.githubusercontent.com/yanganto/nvim-translate/master/snapshot2.png)
It is done in Python
Try to RIIR
Rust Develop Cycle
-
coding
-
cargo check
-
cargo test
Let's do it
- Download nvim config https://bit.ly/2Xv6Hin
- untar and copy nvim folder to ~/.config
- (optional) modify ~/.config/init.vim to your github
- (optional) fork this projct https://github.com/yanganto/coscup
- nvim :Pluginstall
- cd ~/.config/nvim/plugged/coscup cargo build
- Yes, It is ready to go
You also can try neovide
Have fun with Rust
Q & A
Thanks for listening
Find your interesting side project & share!
COSCUP2020
By Antonio Yang
COSCUP2020
This workshop helps people have fun with Rust in Taiwain.
- 1,402