Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement and document interactive mode #5

Open
jreiser opened this issue Nov 27, 2017 · 4 comments
Open

implement and document interactive mode #5

jreiser opened this issue Nov 27, 2017 · 4 comments

Comments

@jreiser
Copy link

jreiser commented Nov 27, 2017

Rustfilt can also accept data from stdin, and pipe to stdout:

When accepting input from stdin, then does rustfilt flush() the output after each individual translation, so that it can be used interactively? This important property deserves explicit documentation.

@luser
Copy link
Owner

luser commented Nov 28, 2017

Rust streams aren't buffered by default, and the code isn't using a BufWriter, so this should work fine. I just tested locally and output is printed after entering each line. I'd be happy to take PRs to improve the documentation!

@jreiser
Copy link
Author

jreiser commented Nov 28, 2017

Rust streams aren't buffered by default, and the code isn't using a BufWriter

If this implies a write() system call for each output character, then that is too expensive when translating an input file with dozens of lines. We want only one write() per completely-translated symbol in order to be both efficient and interactive. Therefore, use a BufWriter with 4096 bytes, and flush it immediately after each translation. (Of course a very long translation might require intermediate flushes, which should be handled implicitly by BufWriter.)

As for documentation, in README.md after the example that follows "Rustfilt can also accept data from stdin, and pipe to stdout:" then add "Each translation is output immediately after it is computed, so that rustfilt can be used interactively."

@luser
Copy link
Owner

luser commented Nov 28, 2017

I'm pretty sure it's a single write per line. Running strace locally shows that to be true:

luser@eye7:/tmp$ strace -o /tmp/rustfilt-trace rustfilt
_ZN96_$LT$core..fmt..Write..write_fmt..Adapter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..fmt..Write$GT$9write_str17h684f82b7d49c77c3E
<core::fmt::Write::write_fmt::Adapter<'a, T> as core::fmt::Write>::write_str
_ZN96_$LT$core..fmt..Write..write_fmt..Adapter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..fmt..Write$GT$9write_str17h684f82b7d49c77c3E
<core::fmt::Write::write_fmt::Adapter<'a, T> as core::fmt::Write>::write_str
luser@eye7:/tmp$ grep write /tmp/rustfilt-trace
write(1, "<core::fmt::Write::write_fmt::Ad"..., 77) = 77
write(1, "<core::fmt::Write::write_fmt::Ad"..., 77) = 77

@jreiser
Copy link
Author

jreiser commented Nov 28, 2017

Great! Then adding a sentence to emphasize the possibility of interactive use is all that remains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@luser @jreiser and others