Is it possible to take any Rust code and make it work in only one line (without any line breaks)? In particular, it should work exactly like the "normal" multi line code:
- if it's an executable, the runtime behavior should be the same.
- if it's a library, the documentation and
.rlib
file should be the same.
This is a purely theoretical question and I don't plan on actually writing my Rust code like this :P
I know that most typical Rust code can be written in one line. Hello world is easy-peasy:
fn main() { println!("Hello, world"); }
Are there any Rust constructs that can't be written in one line? I thought of a few candidates already:
- Doc comments. I usually see them written as
///
or//!
and they include everything until the end of the line. - Macros, especially procedural ones, can do some strange unexpected things. Maybe it is possible to construct macros that only work on multiple lines?
- String literals can be written over multiple lines in which case they will include the linebreaks. I know that those line breaks can also be written as
\n
, but maybe there is something about multi-line strings that does not work in a single line? Maybe something something about raw string literals? - Maybe some planned future extensions of Rust?
- Probably many other things I didn't think of...