These are chat archives for rust-lang/rust

18th
Jan 2019
veruma
@veruma
Jan 18 06:45
does anybody know if there is gonna be a rust conference in USA? or is there a website organizes these conferences?
Denis Lisov
@tanriol
Jan 18 07:50
@verilog15 Note that it cannot be mutable without unsafe and I really recommend you don't use unsafe until you fully understand all the implications.
Better stick to a Mutex for interior mutability.
mnivoliez
@mnivoliez
Jan 18 09:37
Hello! I'm currently working on a script installing an environment. For that purpose, the script read a CSV file to download and install dependancies. The target is windows 10. So far the download work as expected. But the installation is not. The script download an executable and try to execute it through the std::process::Command. The first executable download is a msi file. Sadly the command failed telling me that the msi isn't a win32 exec. Have you any idea how can I fix that?
fn install_single_dep(tmp: &Path, dep: Dependance) -> Result<(), Box<Error>> {
    println!("Installing {}", dep.name);
    let exec_path = download_dep(tmp, &dep)?;
    Command::new(exec_path.to_str().unwrap())
        .spawn()
        .expect("failed to execute process");
    Ok(())
}
Tim Robinson
@1tgr
Jan 18 09:42
You’d need to use ShellExecute rather than CreateProcess, and I don’t see anything onCommand that enables ShellExecute
Mason L
@masonl_gitlab
Jan 18 09:45
Hey folks, I've got a gap in my futures understanding, I'm using the 0.3 preview but don't know how to check if a future handle (from spawn_with_handle) is done
Is there a handy-handy macro that I'm missing to try-check if the handle has a value?
mnivoliez
@mnivoliez
Jan 18 09:48
@1tgr Ok but how does shellexecute is working?
Tim Robinson
@1tgr
Jan 18 09:49
ShellExecute is the thing that knows you have to run msiexec.exe when somebody gives you an .msi file
ShellExecute is a (complicated) wrapper around CreateProcess, and Command is only using CreateProcess
toxicafunk
@toxicafunk
Jan 18 09:49
@masonl_gitlab somehting like handle.wait().unwrap()?
Tim Robinson
@1tgr
Jan 18 09:50
Looks like the Rust team encountered this when they were trying to open a http://... URL in the user's browser, which also requires ShellExecute rust-lang/rustup.rs#1117
Mason L
@masonl_gitlab
Jan 18 09:55
toxicafunk: Where does the wait() come from? I'm not seeing it in the docs (and build doesn't find it either).
mnivoliez
@mnivoliez
Jan 18 09:55
@1tgr
Mason L
@masonl_gitlab
Jan 18 09:55
And is there a try_wait?
mnivoliez
@mnivoliez
Jan 18 09:55
I'll try that then
mnivoliez
@mnivoliez
Jan 18 10:42
ok I'll find another way. I got another strange problem
but it may be me misunderstoodign something.
I got a long path, and I try to extract it as a string
but for whatever reason the path is shortened whith a ~ at some point
Denis Lisov
@tanriol
Jan 18 10:44
Windows? Could you show an example?
mnivoliez
@mnivoliez
Jan 18 10:45
The code I try to achieve: let exec_path = download_dep(tmp, &dep)?;
Command::new("cmd").args(&["/C", "start", exec_path.to_str().unwrap()])
the tmp is a path return by tempfile::temp_dir().path()
of tempfile crate
Denis Lisov
@tanriol
Jan 18 10:46
And the path looks like?
mnivoliez
@mnivoliez
Jan 18 10:46
C:\Users\SESA51~1\AppData\Local\Temp\.tmpqH3l0E\blender-2.79b-windows64.msi
as you can see the SESA54~1 isn't quite what I need here
Denis Lisov
@tanriol
Jan 18 10:47
It might actually work with this path :-) have you tried that?
mnivoliez
@mnivoliez
Jan 18 10:47
The path should be C:\Users\SESA514836\AppData\Local\Temp.tmpqH3l0E\blender-2.79b-windows64.msi
when pass into the "cmd" the system politely tells me that it doesn't find the file
"Le système ne peut trouver le fichier C:\Users\SESA51~1\AppData\Local\Temp.tmpqH3l0E\blender-2.79b-windows64.msi."
Denis Lisov
@tanriol
Jan 18 10:50
This kind of path shortening is a Windows "feature" for DOS compatibility. Don't know the exact range of situations where it works :-)
mnivoliez
@mnivoliez
Jan 18 10:54
ok
Denis Lisov
@tanriol
Jan 18 10:59
At least in my Win10 VM cmd /C start "" c:\Progra~2\Micros~1\Office15\winword.exe starts Word correctly.
mnivoliez
@mnivoliez
Jan 18 11:06
ok, I just remove the start command and the stuff worked
Diego Antonio Rosario Palomino
@GunpowderGuy_gitlab
Jan 18 12:52
what would it take to run serde or some other serialization system at compile time ?
Denis Lisov
@tanriol
Jan 18 12:55
Depends on what exactly you want to achieve.
Andreas Franzén
@triptec
Jan 18 13:11
Hello, I'm looking for some advice. I'm trying to write a rust wrapper over vips-cpp. vips-cpp is a cpp wrapper over vips (a image manipulation library). I've just started but I'm already in trouble =). Is there anyone who might have a look at https://gist.github.com/triptec/093edc45a9aaf5598a88927aac554f88, it's the gdb output and I have no clue what's it about
Denis Lisov
@tanriol
Jan 18 13:12
Pretty sure you're not the first person to try wrapping vips...
Was it a segmentation fault?
Andreas Franzén
@triptec
Jan 18 13:15
yeah
segfault
Tim Robinson
@1tgr
Jan 18 13:16
@GunpowderGuy_gitlab it already aims to do as much up-front work as possible at compile time
Diego Antonio Rosario Palomino
@GunpowderGuy_gitlab
Jan 18 17:00
@tanriol i want to parse xml documents into azul's dom at compile time in release builds
Denis Lisov
@tanriol
Jan 18 17:07
Nontrivial. There seems to be no native support for that, which means lots of code generation. Are you sure that the time spent parsing them in your app is actually significant?
verilog15
@verilog15
Jan 18 17:49

Hey guys :)
I know that rust works with Eager order evaluation but I would like to write an example using Rust syntax which will print Lazy if Rust would use lazy evaluation and Normal if it was normal. The code I came up with:

static m: i32 = 0;

fn f(x: i32) -> i32 {
    m += 1;
    return x;
}

fn g(x: i32) -> i32 {
    m += 100;
    return x;
}

fn h(x: i32,y: i32) -> i32 {
    return x+x+x;
}

fn main() {
    let t = h(f(1),g(1));
    if (m == 1) {
        println!("Lazy");
    } else if (m == 3) {
        println!("Normal");
    } else if (m > 100) {
        println!("Eager");
    }
}

I know I have trouble with the mutable m. How can I fix the program?

Ingvar Stepanyan
@RReverser
Jan 18 17:50
Rust would never change evaluation order, so not sure what you're trying to achieve...
Tim Robinson
@1tgr
Jan 18 17:51
Make it a local variable in main, and pass it as m: &mut i32 into f and g
verilog15
@verilog15
Jan 18 17:51
@RReverser Its more of a theoretical question.
@1tgr Is it possible without passing the variable? I would like to leave it be as a global variable so I don't have to evaluate it.
Denis Lisov
@tanriol
Jan 18 17:54
@verilog15 Are these questions assignments in your programming class?
verilog15
@verilog15
Jan 18 17:54
@tanriol Yes, It said to choose a language. So I choose Rust :)
Tim Robinson
@1tgr
Jan 18 17:57
@verilog15 a mutable static isn't really going to work unless you jump through a lot of hoops
As a minimum, you'd need to put it in a Mutex initialized via lazy_static!
No harm in passing it as a function parameter though, doing it that way doesn't change the logic, and it's the idiomatic way to do it
That is, mutable static is not idiomatic in Rust
Incidentally the whole program optimizes down to just println!("Eager");
Ingvar Stepanyan
@RReverser
Jan 18 18:01
well for types supported in static at all you don't really need lazy_static, it's a bit of overkill
and the only hoop you would need to jump through nowadays is put unsafe around assignments
but yeah, that's usually a bad idea and better to just pass parameter around
Tim Robinson
@1tgr
Jan 18 18:34
I don’t think you can initialise a static variable with a Mutex?
Ingvar Stepanyan
@RReverser
Jan 18 18:34
you don't need Mutex either
Tim Robinson
@1tgr
Jan 18 18:35
RefCell isn’t enough as it’s not Sync
Ingvar Stepanyan
@RReverser
Jan 18 18:35
You don't need any wrapper...
Tim Robinson
@1tgr
Jan 18 18:35
(assuming we’re not going with unsafe)
Ingvar Stepanyan
@RReverser
Jan 18 18:35
Literally just i32
Well I did say that it will require unsafe :)
Tim Robinson
@1tgr
Jan 18 18:36
I hope we can avoid unsafe on an introductory programming assignment
Ingvar Stepanyan
@RReverser
Jan 18 18:38
Where's a fun in that :P
Sylwester Rąpała
@xoac
Jan 18 20:25
What about atomicIsize? If i32 can be replaced? There should be also crates for atomicI32 until it lands in stable ;)