Follow

How well do the new Rust CLI tools play with pipes?

@codingquark what is your concern here? In my experience #Rust #CLI tools like bat or ripgrep work perfectly fine with pipes. You shouldn't notice that they are written in #Rust when you use them.

@schrieveslaach I was not switching to the tools *assuming* they're new and therefore need time to mature before they start playing well with pipes. Looks like they actually do play well!

@codingquark @schrieveslaach Pipe behavior is mostly implemented by the shell/libc/OS, so not really a language-specific issue. The only difference is that Rust's standard library defaults to handling Broken Pipe signal as a regular I/O error instead of killing the process. But Rust does error handling pretty well generally.

@kornel @codingquark I know that std(in|out|err) redirection is handled by the operating system efficiently. However, you can screw up the performance of an application easily. For example, in #Java you can write an application that reads from stdin in a very inefficient way. A couple of month ago I had to fix such a bug at work. Therefore, the concern is legitimate.

@schrieveslaach @kornel @codingquark

In #Rust you can also be inefficient when reading e.g. stdin.
You should call stdin.lock() before reading in order to access `BufRead`'s methods, like `lines()`.
See docs on the `std::io::Stdin` docs:
doc.rust-lang.org/std/io/struc

And `BufRead`:
doc.rust-lang.org/std/io/trait

Sign in to participate in the conversation
Mathstodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!