WezM.net Menu

Rust Tools Talk

Published on Wed, 28 September 2016

Supporting Rust by using Rust: An exploration of great tools written in Rust

I presented at the September Melbourne Rust Meetup. My talk was about some of the great tools that are being built in Rust, the benefits that brings and how using and promoting these tools can help with the wider adoption of Rust in the development community. I demonstrated a selection of such tools.

A video of the talk will be made available, but it’s not ready yet.

The slides are available online. The presenter notes I wrote for myself are included below.

Slide Notes

Promoting Rust

Why Rust tools are great

Demos

Some notes on the demos that I’ll be performing:

watchexec - Executes commands in response to file modifications

https://github.com/mattgreen/watchexec

Example:

Watch rust dir, echo changed files on touch

watchexec -w src 'echo $WATCHEXEC_UPDATED_PATH'

Other terminal:

touch src/libstd/collections/hash/map.rs
touch src/libstd/collections/hash/set.rs

fd - A simple, fast and user-friendly alternative to find.

https://github.com/sharkdp/fd

You might be familiar with find, for finding files by name:

find . -name '*option*'

It’s pretty quick but there’s a bunch of typing for the common case of just wanting a partial match on filename.

fd does the same thing with a simple interface for that common case, while honoring .gitignore, coloured output and smart case for matching (no need for iname/name.

fd option

The pattern is a regular expression instead of a glob. The current directory is the implied path to search if not specified.

fe - A super-fast and easy to use fuzzy file searcher

https://github.com/btipling/fe

fe is similar to fd except that it’s a fuzzy matcher. It uses a smart fuzzy search algorithm similar to that used in IDEs and editors for finding files.

Searches start matching at word start, and on match failure stop matching until the next word

Example:

fe lopt

You can see we got fewer results with a shorter pattern.

exa - a modern replacement for ls

https://the.exa.website/

exa is a replacement for ls with helpful defaults like human readable files sizes, colourized output for permissions, file type, and a tree view.

Example:

exa -lh

Here we see exas table output (-l). (-h) adds headers. You can see that colour is used to help group similar concepts.

Tree view:

exa --tree src/etc/installer

Colour scale for file sizes:

exa -l --colour-scale ~/Downloads

The larger the file the more intense the colour, shifting from green to yellow.

It also has git integration and can show the status of files tracked in git.

exa calls itself a replacement for ls, which I think is accurate. I have ls aliased to it in my shell:

which ls

rg - the usability of The Silver Searcher with the raw speed of [GNU] grep.

https://github.com/BurntSushi/ripgrep/

You may have heard of ack, or the silver searcher. They are tools to rapidly search the content of files in a directory tree, often code. A faster version of grep -r that ignores binary files, files ignored by git ignore file ripgrep is a similar tool: Fast code search (regex) honoring git ignore without optional filtering by language.

Great blog post by the author (Andrew Gallant) that compared ripgreps performance and correctness to similar tools.

Example 1:

rg Option

If you blinked you may have missed that but about 11,000 were checked.

Example 2:

rg รจ

rg has complete support for Unicode

Example 3:

ripgrep knows about file types and regexes so if we want all function that contain into and return a String (on one line):

rg -t rust 'fn.+into.+-> String'

alt - Command line tool to find alternate files

https://github.com/uptech/alt

alt prints the alternate for a file. Has editor integration so you can do it in you favourite editor (Neovim). Works well for languages that have file pairs. In my case I work on Ruby apps, which have spec files in a tree mirroring the app tree. For example in pkb, which is a Rails app I wrote:

Example:

alt app/models/page.rb

Ignore the trailing %, that’s my shell telling me the output didn’t end in a new line. This one is super helpful in your editor to switch to the “alternate file”.

tac

https://neosmart.net/blog/2017/a-high-performance-cross-platform-tac-rewrite/

tac is a Rust implementation of the tool with the same name commonly only found on Linux systems. It prints the lines of a files in reverse. This can come in handy when dealing with large log files.

Example:

We have a 3.8Gb log file. We want to see the last request in the log that was made by a visitor using the Opera web browser with the Presto rendering engine:

grep Presto ~/Documents/webserver.log | tail -n1

That’s great but it took a little while, we can do better with tac:

tac ~/Documents/webserver.log | grep Presto | head -n1

Yay quick!

dot - Yet another management tool for dotfiles

https://github.com/ubnt-intrepid/dot

Dot is a dot file manager. It can automatically clone a git repo then symlink the files according to a mappings file. You can have mappings that are OS specific. It’s a single binary so downloading and bootstrapping a new system is easy.

Hard to demo but my dotfiles are managed with it:

https://github.com/wezm/dotfiles

titlecase - Capitalise text according to a style guide

https://github.com/wezm/titlecase

Example:

In vim filter some text through it:

Before:

The iPhone X: “a detailed guide to designing for a notch”

After:

The iPhone X: “A Detailed Guide to Designing for a Notch”

vim demos/titlecase.md
# duplicate the line so you can see before and after
:'<,'>!titlecase

Notes:

ion shell - A shell written in Rust for Redox and Linux

https://github.com/redox-os/ion

Lastly if you feel like living on the edge… There is a project called Redox to build an operating system in Rust. They’ve made a stack of progress so far and one of the components they’ve build is a shell called ion, which also runs on Linux. It has some neat features reminiscent of the fish shell.

Example:

ls
ls -lh
which ls

As you can see it works, it’s not full of features yet so probably not ready for full time use. Maybe try it out to hep test it, report any issues you find.

wesers - Single file webserver

https://github.com/wdv4758h/wesers

Depending on time:

Are you the next great tool author

Conclusion

Comment icon Something to Add?

Contact me by email, Twitter, or Mastodon if you have a comment, correction or just want to get in touch.