These are chat archives for rust-lang/rust

30th
Apr 2018
Dylan DPC
@Dylan-DPC
Apr 30 2018 06:58
@kellytk they have a slack channel
Ayushya Chitransh
@AyushyaChitransh
Apr 30 2018 08:14

I am trying to use https://doc.rust-lang.org/std/process/struct.Command.html to invoke a function, but I want to handle the case when that command is not found.

expectation:
-bash: solc: command not found

Actual:
Permission denied (os error 13)'

Ayushya Chitransh
@AyushyaChitransh
Apr 30 2018 08:21
For more context, here is the code I am trying to run:
match Command::new("solc")
            .arg("--version")
            .output()
            {
             Ok(exit_status) => {
                let output_string = String::from_utf8(exit_status.stdout).unwrap();
                let solc_version = output_string.lines().last().unwrap();
                println!("cargo:rustc-env=SOLC_VERSION={}", solc_version);
             }
             Err(err) => {
                if let std::io::ErrorKind::NotFound = err.kind() {
                panic!("`solc` executable not found in `$PATH`.");
            } else {
                panic!("an error occurred when trying to spawn `solc`: {}", err);
              }
            }
         }
Ayushya Chitransh
@AyushyaChitransh
Apr 30 2018 09:06
Here is the question where I have described the problem more clearly: https://stackoverflow.com/questions/50097272/check-using-rust-if-a-program-is-installed
Michal 'vorner' Vaner
@vorner
Apr 30 2018 10:21
You probably want to use the which command (shell command) to do these kinds of checks.
Nicolas Almy
@almynic
Apr 30 2018 12:37
Hi all. Is there something similar to a Java properties file which can be loaded at runtime in Rust? I have a program which should run on different platforms and need to be configured for each platform.
Michal 'vorner' Vaner
@vorner
Apr 30 2018 12:43
You mean something like config file? (Sorry, I have no idea about Java) https://crates.io/crates/config
Nicolas Almy
@almynic
Apr 30 2018 12:47
yes like a config file. Thanks for the link will try that out.
Jan Hlavatý
@hlavaatch
Apr 30 2018 16:46

I'm trying to initialize some win32 API structures that are supposed to be zeroed out and their length set. Which one is better/does not copy empty instance around?

let mut ms = MEMORYSTATUSEX { dwLength: size_of::<MEMORYSTATUSEX>() as DWORD, ..unsafe {zeroed()} };

or

let mut ms: MEMORYSTATUSEX = unsafe { zeroed() }; ms.dwLength = size_of::<MEMORYSTATUSEX>() as DWORD;

?

I would like to see some assembly/map file output but didn't manage to on windows...
Jan Hlavatý
@hlavaatch
Apr 30 2018 17:07
let mut ms = MEMORYSTATUSEX { dwLength: size_of::<MEMORYSTATUSEX>() as DWORD, ..unsafe {zeroed()} };
0000000140001034: C7 44 24 28 40 00  mov         dword ptr [rsp+28h],40h
                    00 00
  000000014000103C: 0F 57 C0           xorps       xmm0,xmm0
  000000014000103F: 0F 11 44 24 58     movups      xmmword ptr [rsp+58h],xmm0
  0000000140001044: 0F 11 44 24 4C     movups      xmmword ptr [rsp+4Ch],xmm0
  0000000140001049: 0F 11 44 24 3C     movups      xmmword ptr [rsp+3Ch],xmm0
  000000014000104E: 0F 11 44 24 2C     movups      xmmword ptr [rsp+2Ch],xmm0
  0000000140001053: 48 8D 4C 24 28     lea         rcx,[rsp+28h]
  0000000140001058: E8 F3 82 01 00     call        GlobalMemoryStatusEx
let mut ms: MEMORYSTATUSEX = unsafe { zeroed() }; ms.dwLength = size_of::<MEMORYSTATUSEX>() as DWORD;
  0000000140001037: 0F 57 C0           xorps       xmm0,xmm0
  000000014000103A: 0F 29 44 24 30     movaps      xmmword ptr [rsp+30h],xmm0
  000000014000103F: 0F 29 44 24 60     movaps      xmmword ptr [rsp+60h],xmm0
  0000000140001044: 0F 29 44 24 50     movaps      xmmword ptr [rsp+50h],xmm0
  0000000140001049: 0F 29 44 24 40     movaps      xmmword ptr [rsp+40h],xmm0
  000000014000104E: C7 44 24 30 40 00  mov         dword ptr [rsp+30h],40h
                    00 00
  0000000140001056: 48 8D 4C 24 30     lea         rcx,[rsp+30h]
  000000014000105B: E8 F0 82 01 00     call        GlobalMemoryStatusEx
Ok, code is different, but which is better?
Jan Hlavatý
@hlavaatch
Apr 30 2018 17:14
second one is nicer to the caches I'd guess
scottmcm
@scottmcm
Apr 30 2018 19:36
I suspect it doesn't matter.
Also, bunny was contemplating a safe wrapper for zeroing these things; I dunno if that got in...