Last active
December 29, 2022 12:10
-
-
Save ruxo/4d124d02c28e0cff6560a536441fa841 to your computer and use it in GitHub Desktop.
.NET-like Console functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::{stdin, Error}; | |
| /// Write text output into STDOUT with string format supported. Like .NET `Console.Write()` | |
| #[macro_export] | |
| macro_rules! console_write { | |
| ($($args: tt)*) => {{ | |
| print!($($args)*); | |
| std::io::Write::flush(&mut std::io::stdout())?; | |
| }}; | |
| } | |
| /// Write text output into STDOUT with string format supported. Like .NET `Console.WriteLine()` | |
| #[macro_export] | |
| macro_rules! console_writeline { | |
| ($($args: tt)*) => {{ | |
| println!($($args)*); | |
| std::io::Write::flush(&mut std::io::stdout())?; | |
| }}; | |
| } | |
| /// Read a string from STDIN. Just like .NET `Console.ReadLine()` | |
| pub fn read_line() -> Result<String, Error> { | |
| let mut s = String::new(); | |
| let len = stdin().read_line(&mut s)?; | |
| s.truncate(len - 1); | |
| Ok(s) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment