Rust Workshop - iBriz academy 2022

This was the reference to which I presented an hour long workshop within iBriz Academy. This contains broad introduction ( not too depth ) to introduce anyone who is familiar with programming in general. I also showcased my ytui-music project.

Rust crab looks happy

What will we discuss

  • What are we using in our current project
    • Rust
    • Substrate
    • Polkadot.js
    • Lots and lots of communication and helping each other
  • Why Rust for blockchain
  • Why rust even for anything else
  • See a project (ytui-music) developed entirely on rust
  • Have a high level understanding of how ytui-music work
  • Navigate a bit of code here and there
  • Future of rust and where else we can expect it to emerge
  • Reaching me out

Ytui-music

Listen to music from youtube in terminal with decent tui

Why use ytui-music

  • Never get tracked by youtube on your listening preference
  • Downloading music made easiest
  • Save machine resource for other useful task by avoiding browser
  • Use on remote ssh or terminal-only session
  • Completely keyboard driven usage ( feed the cats with mouse )
  • Configurable ui and other preferences with easy json file
  • Open sourced codebase to make it all yours

Screenshots

====> See direct demo <=====

Highlights from demo

  1. Search according to types. eg: music, playlist, artist, all
  2. See trending feed
  3. Pagination with p and n
  4. Responsive design
  5. Configurable with easy json
    • Default for dark theme, can be made for light
  6. Saved data in sqlite format
  7. suffle/ repeat/ play pause
  8. Volume control in master branch
  9. configurable mpv => configurable youtube-dl
  10. navigation
  11. download

Tools and Libraries used

  1. Rust ( https://github.com/rust-lang/rust/ ) - to write ideas
  2. Invidious (https://github.com/iv-org/invidious)
    • middleware to serve youtube data in easy api
  3. Mpv (https://github.com/mpv-player/mpv)
    • Used for playback
    • Supports youtube link out of the box as regulat file input
    • Not-so-heavy and comes with configurable options
    • Provides well documented and easy C api
  4. libmpv-rs ( https://github.com/ParadoxSpiral/libmpv-rs )
    • Rust binding for mpv
  5. tui-rs ( https://github.com/fdehau/tui-rs )
    • Allows developing tui with rust
    • Supports multiple backends like termion, crossterm etc.
  6. Corss-term ( https://github.com/crossterm-rs/crossterm )
    • Used internally by tui-rs ( for this project )
    • Support keyboard ( as well as mouse ) event handeling
  7. Youtube-dl ( https://github.com/ytdl-org/youtube-dl )
    • Downloading of music from youtube server
    • Internally used by mpv for youtube-music playback
  8. Sqlite (https://sqlite.org/src/)
    • Store favourates on local system
  9. Neovim, Rust-analyzer, COQ_nvim, Typora, action-rs …. - for development proposes
  10. Github ( https://github.com ) - For hosting suorce code

Working Mechanism

You might want to work on

Depending on what you have already been into

UI

  • Add pop ups and over-screen widgets
  • Optional audio visualizer
  • Configurable section size or even more configuriable layout
  • Pre-configured colour scheme

Web/ Network/ Scraping

  • Add support for spotify or other services like deezer, apple music
  • Deploy own invidious server
  • Music recommendation based on listening activity ( youtube’s recommended for you list )

Media handling

  • Allow custom playback
  • Filters and mixing

Database

  • Custom playlist ( other than favorates )
  • Most listened songs
  • Import playlist from youtube favourates

Others..

  • Performance optimization
  • Another rust binding for libmpv
  • Docs
  • And whatever you want to

Why rust for ytui-music & anything else?

  • Good to go concurrency

    • Cross platform abstracted concurrent programming

    • First class async support in addition

    • Lifetime to say goodbye to deadlock, global variable override and segfault

    • Mutex, ConditionVariable, Arc & Rc to make things even better

  • Safe and well-designed library

    • Rs-tui - a library that makes developing tui fun and crossplatform
    • libmpv-rs - safe and abstract binding over mpv player
    • reqwest - easy and battery-included http library
    • serde - life saver to work with popular human-redable format
  • Forces to write GOOD code

    • Never create copy when you can move
    • simplify similar logic with declerative macros ( not same as generic though )
    • make writing platoform-dependent code more easy with conditional macros
  • And lot more…

Build file in rust

img

Great innovation with documentation & Testing

  • Makes writing documentation fun, easy and encouraging

  • Super easy to generate documentation

    cargo doc

  • Super easy documentation navigating web-pages with heavy interlinking

    Click - click - click

    * A quick navigation in docs.rs

  • Support for documentation code snippet checking

    Keep code example in sync with changes in codebase

  • Built-in test framework & benchmarking framework

    * Writing test doesn’t add complexity in logic

    * Full freedom with macros like #[cfg(test)]

Configurable formatting

  • Cargo fmt

    ====> Lets see a demo

Future of Rust

Team behind Rust

  • The Rust Foundation

    * Non profit organization with bigger vision and devoted community

    * https://foundation.rust-lang.org/

    * Backed by tech gaints including but not limited to Google, Mozilla, Linux Foundation, Meta Inc (Facebook), Microsoft, Huawei ….

Blockchain Development

Embedded system & IOT

Kernel Development

Cloud Computing, IOT and embeded system

Web Development

  • Soon-to-be mature asynchronous ecosystem with tokio

  • Web Framework

    • Actix web: https://actix.rs/

      Benchmark proves it to be fastest web framework

      Support completly async programming

    • Rocket-rs: https://rocket.rs/

      Easiest to start with

      Full async support

      Great documentation

    Personal utilities and fun projects

  • Ever-growing ecosystem for libraries and framwork

  • Community to turn to when needed

  • Fun to write

  • Easy to maintain

  • Easy to reason about so easy for contributers

The community inside rust

===> We have already talked about this <===

Respects existing era

===> We have already talked about this <===

While developing along the way

Might not be all roses

What is Rust not for (yet)

  • AI/Ml
  • Mobile development
  • Enterprise reasy gui development ( may be a good go within next week! who knows? )
    • Although tools like gtk-rs, qt-rs, sixtyfps are standing out to be leading tools
    • Tauri-rs already being used in replacement of electron

Lots of compile time nap

img

​ Image credit: cnbc.com

  • Slow to compile ( you can travel galaxy when you leave your project to compile for release )

    * https://blog.rust-lang.org/2020/12/16/rust-survey-2020.html#compile-times

  • Have to do a lot of checks and macro expansion

  • Aggressive optimization in release mode

  • Pack lots of helpful debug information and detailed tracebacks

  • LLVM is not so compile time friendly (have several technical debts and code from every generation)

  • Many tactics and tools to make it a breeze

    • Do not always build in release mode
    • Make use of cargo check and cargo watch
    • Test in test cases instead of testing it the-human-way by seeing logs
    • Use an lsp for instant feedback
    • Think more before you run

And …

  • Not so old enough to have a planet-heavy ecosystem as compared to C or Python
  • Do not have that much vast majority of developer. ( Pretty impressive how everybody knows javascript )
  • Do not runs on 3 millions of devices like Java ( instead Rust is about to run on billions )
  • Increase your frustration as compiler always throws error of every possible error (which is actually a benefit in long run)
  • Not so quick to write prototyes

Reaching me out

About me

let me = Human {
    name: "Sudip Ghimire",
    location: "Pokhara",
    academic_qualification: "+2 passout",
    Professional_experience: [
        						"Web developer intern - Codesastra (2019)",
        						"Rust developer - iBriz.ai (2021)"
    						],
    email: ["sudipghimire533@gmail.com", "sudipg@ibriz.ai"],
    github: "github.com/sudipghimire533",
    website: "me.sudipg.com.np",
    blogs: "sudipg.com.np"
}

You have the power

You can Edit this article or even Submit new articles. Want to Learn more?