Beginner's code review

  1. Is using crate clipboard-win the best (short for dev and effective for PC) way to get text from clipboard ? Is it only for Windows ? What about Linux ?
 [deps]
clipboard-win
let my_clp: String = clipboard_win::get_clipboard(clipboard_win::formats::Unicode).expect("to get_clipboard");

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  1. ?
if ... {
    println!(   "Not found ...")  ; // Need attention before closing
    std::io::stdin().read_line(_); // Dont want to create a mut String
    return;   // How to keep terminal in Win ? Need pause
}

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  1. How do you get executable's name ?
let my_app: Vec<String> = std::env::args().collect();
let mut my_app = std::fs::OpenOptions::new()
.append(true) 
.create(!false)
.open(

std::path:: Path::new(  
    
 std::path:: Path::new(  & my_app  [0]      ). file_stem(    )      .unwrap()  
 
).with_extension(    "log"  )
)
.expect("To open log")
;   

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  1. What is easy way to get timestamp ? Is it necessary to download a crate?
 [deps]
chrono  = "0.4"
let my_log: & str   =  & format !(  " {}" 
,   chrono   ::  Local   :: now  (   ) .   format  (   "%a %e.%m.%Y %H:%M:%S"   )  //  .to_rfc2822()    //
)   ;
println !   (   "{} "    ,  my_log    ) ;

Check out clipboard crate for cross platform compatibility

1 Like

You don't need chrono for basic time operations. The standard library has std::time.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.