deepr_utils/
common.rs

1use std::{env, io};
2
3pub fn print_type_of<T>(_: &T) {
4    println!("{}", std::any::type_name::<T>())
5}
6
7pub fn print_environment_variables() {
8    for (k, v) in env::vars() {
9        println!("{}, {}", k, v);
10    }
11}
12
13pub fn read_from_stdin() -> Result<String, std::io::Error> {
14    use std::io::prelude::*;
15
16    let mut buffer = String::new();
17    let mut stdout = io::stdout();
18
19    write!(stdout, "Select URL key or type exit to quit program : ")?;
20    stdout.flush()?;
21
22    io::stdin().read_line(&mut buffer)?; // includes '\n'
23    Ok(buffer)
24}
25
26pub fn pause_stdin() -> Result<(), std::io::Error> {
27    use std::io::prelude::*;
28    let mut stdin = io::stdin();
29    let mut stdout = io::stdout();
30
31    // We want the cursor to stay at the end of the line
32    // so we print without a newline
33    write!(stdout, "Press any key to continue...")?;
34    stdout.flush()?;
35
36    // Read a single byte and discard
37    let _ = stdin.read(&mut [0u8])?;
38
39    Ok(())
40}