用小齒輪來帶動大齒輪 - 用Rust做Rust的開發工具

How to learn?

By writing some side projects

Asking for

Rust Project ?!!

Asking for Rust Side project ???

What is Trait of Rust ?

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)

Trait of Rust

Peak and periodic

Smooth and constantly

Trait of Rust

X coordinate is Date !

Lack a lot of things

but a lot of side projects

 

:)

Rust Daily and RIIR

How to find a Rust Side project ???

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

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.

wtftw

Window Tiling For The Win. A tiling window manager written in Rust

Neovide

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.

It is really cool

RON? what is this?

RON - Rusty Object Notation

RIIR

A little bit crazy?

Why RIIR

Efficacy &

Safe

use Rust

  • Participate it
  • And learn more

Still Why Rust?

System Call for Windows Server running IIS.

Find the line with error

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)
    }
}

pub fn home_dir() -> Option<PathBuf>

Result

fn sqrt(x: f64) -> Result<f64, &'static str> {
    if x < 0.0 {
        Err("Do not sqrt the negative number")
    } else {
        Ok(x.sqrt())
    }
}

pub fn current_dir() -> Result<PathBuf>

Rust don't put wires into box and pretend clear

"DSCF2319.JPG"  by em978 is licensed under  CC BY-NC 2.0 

Rust make every thing ordered

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?

"IMG_3461" by Jemimus is licensed under CC BY 2.0

Where are scissors & tape ?

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

That is my scenario

It is done in Python

Try to RIIR

Rust Develop Cycle

  1. coding
  2. cargo check
  3. cargo test

Let's do it

  1. Download nvim config  https://bit.ly/2Xv6Hin
  2. untar and copy nvim folder to ~/.config
  3. (optional) modify ~/.config/init.vim  to your github
  4. (optional) fork this projct https://github.com/yanganto/coscup
  5. nvim :Pluginstall
  6. cd ~/.config/nvim/plugged/coscup cargo build
  7. 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!

Made with Slides.com