These are chat archives for rust-lang/rust

20th
Feb 2018
Kelly Thomas Kline
@kellytk
Feb 20 2018 01:42
Is println thread-safe? In other words, calling it from multiple threads potentially concurrently
Ryan
@rnleach
Feb 20 2018 02:40
@kellytk Yes, I think it is, but I can't remember where I read that now. However, your calls may be interleaved in any random order, so if you print multiple lines from different threads they get interleaved, but each line will be complete. Basically, iirc it uses a mutex internally to access stdout.
Kelly Thomas Kline
@kellytk
Feb 20 2018 03:09
Thanks @rnleach
Adel Prokurov
@aprokurov
Feb 20 2018 05:42
What is wrong here?
pub fn execute(command: String) {

    let output = Command::new(command)

        .output().unwrap_or_else(|e| {
            panic!("failed to execute process: {}", e)
    });
    if output.status.success() {
        let s = String::from_utf8_lossy(&output.stdout);

        print!("succeeded and stdout was:\n{}", s);
    }
}
fn main() {

    let command = String::from("uname -r");
    execute(command);

}
thread 'main' panicked at 'failed to execute process: No such file or directory (os error 2)', src/command_exec.rs:9:13
Hans W. Uhlig
@huhlig
Feb 20 2018 05:46
looks like what you tried to run doesn’t exist
most likely cause uname -r is invalid
you want "/usr/bin/uname”, “-r” or similar
hmm
looks like you want
let output = {
  Command::new(“/usr/bin/uname”)
    .args(“-r”)
    .output()
    .expect("failed to execute process")
};
Adel Prokurov
@aprokurov
Feb 20 2018 05:52
thanks
Matías Fidemraizer
@mfidemraizer
Feb 20 2018 09:46
hey, how's going
I've some question. I'm intrigued by Rust and the chance to implement code using FP practices
I've read about the topic around the net but most posts are from 2014-2015. Do you know any good resource about the topic?
Denis Lisov
@tanriol
Feb 20 2018 09:47
Rust in general or something more narrow?
Matías Fidemraizer
@mfidemraizer
Feb 20 2018 09:47
FP
functional programming
Matías Fidemraizer
@mfidemraizer
Feb 20 2018 09:53
for example, I've found this https://github.com/danslapman/rust-mdo-future which looks promising
but it seems like it's abandonware
Tom Cumming
@tomcumming
Feb 20 2018 09:55
@mfidemraizer rust cant type monads because it doesnt have higher kinded types, so do notation doesnt make much sense
Matías Fidemraizer
@mfidemraizer
Feb 20 2018 09:57
anyway, it seems like there's still no FP standard library with monads, functors, and so on
am I mistaken?
Aleksey Kladov
@matklad
Feb 20 2018 09:58
@mfidemraizer yep, you are correct. Moreover, Rust is actually pretty far from being an FP language, so you probably will be disappointing if you try to apply FP patterns to rust verbatim.
Tom Cumming
@tomcumming
Feb 20 2018 09:58
you cant have a monad nor functor trait (like a type class) unfortunately
Matías Fidemraizer
@mfidemraizer
Feb 20 2018 10:02
I see
I was just curious about the language. Not only in terms of FP, but as I'm currently advancing on my knowledge about FP (and I'm currently implementing a project with FP), and I found Rust really interesting, I thought I could give it a try for this
Aleksey Kladov
@matklad
Feb 20 2018 10:11
Yeah, Rust is definitely interesting, but I wouldn't suggest approaching it from an FP or OO angle, because it is neither. A nice approach to learning might be to read the book first and than try to implement some small projects (just in "Rust", not "fp Rust" or "oo Rust" or "C++ Ruste") to figure out language unique idioms and trick (there are may of them due to lifetimes) .
Matías Fidemraizer
@mfidemraizer
Feb 20 2018 10:12
@matklad thank you for the advise
Aleksey Kladov
@matklad
Feb 20 2018 10:14
@mfidemraizer ohhh, I've just remembered this (fresh) blog post which nicely exemplifies how FP might look very different in Rust: http://smallcultfollowing.com/babysteps/blog/2018/02/01/in-rust-ordinary-vectors-are-values/
Matías Fidemraizer
@mfidemraizer
Feb 20 2018 10:17
@matklad interesting, I'll re-read it carefully tonight
Edouard Menayde
@edouardmenayde
Feb 20 2018 11:13
Hi, i'm working on a command line file sharing utility with rust. I am currently using the cliboard crate which is great but as stated in this issue aweinstock314/rust-clipboard#28 the setted content does not outlive the process. I even tried using a clipboard manager for my gnome setup as suggested in the issue but it does not solve the issue. Has anyone an idea on how to find a way to deal with this besides having my cli running as a daemon ?
John-John Tedro
@udoprog
Feb 20 2018 12:07
@edouardmenayde IMO, the library should better integrate with external
... clipboard managers. Qt, GTK, Windows, and OSX all have facilities that takes ownership (or equivalent) of copy paste buffers IIRC.
Martin Hafskjold Thoresen
@martinhath
Feb 20 2018 13:48
Hey all, is there some way to detect that the process is being shut down? I'm doing weird stuff, so in a Drop impl I'm locking a Mutex (from lazy_static!), but this panics if i use .lock() saying cannot access stdout during shutdown. With try_lock() it's fine, but then it's seemingly not possible to find out if I get back Err because the process is shutting down or if just another thread has the lock. Any ideas?
Neverminder
@Neverminder
Feb 20 2018 14:07
how to convert i64 to i32?
Jonas Platte
@jplatte
Feb 20 2018 14:24
@Neverminder
let a: i64 = 3;
let b: i32 = a as i32;