These are chat archives for rust-lang/rust

1st
Feb 2017
Gugan Arumugam
@agugan
Feb 01 2017 10:37
I am planning to build android app and iOS app with React Native. So I thought of isolating the certain business logic to a REST API. First thought of going with kotlin, but since JVM needs like a minimum 4GB + 2vCPU on production server(budget problems) thought of going with non jvm languages. My options were C++ or RUST. What's your take on this?
Ewan Higgs
@ehiggs
Feb 01 2017 11:42
Gugan, consider Go.
It's a simple language and has a modest footprint. If you get your prototype working with Go and find it's too resource hungry then consider porting it to Rust or C++.
Thomas Jay Rush
@tjayrush
Feb 01 2017 13:22
I am 100% C++, and have been since 1984. But...I would definitely choose Rust over C++ if I was just getting started for a single reason: crates.
Jarred Nicholls
@jnicholls
Feb 01 2017 13:53
@agugan definitely Rust or Go imho.
Sergey Noskov
@Albibek
Feb 01 2017 13:55
You can only vote for Rust in Rust channel!
Ewan Higgs
@ehiggs
Feb 01 2017 14:12
@Albibek , I think you're joking, but the Rust web story is under heavy development so if you're going to make a service for production, go all in and help bring the web story to life. Or just use Go which is a pretty handy language; but keep an eye on Rust.
Sergey Noskov
@Albibek
Feb 01 2017 14:13
Sure I'm joking
salpalvv
@salpalvv
Feb 01 2017 15:07
@agugan I had success using Go + gRPC (this wasn't one of your options but others mentioned Go) for an android app backend. I just hate their vendoring / package management toolchain. Between your choices, I would use Rust.
Ed Lewis
@ninjabear
Feb 01 2017 16:25
@salpalvv just interested in gRPC - have you tried using gRPC with a rust crate?
seems that most grpc crates have a big don't use yet disclaimer on them currently
salpalvv
@salpalvv
Feb 01 2017 16:32
@ninjabear Yeah I haven't seen a rust gRPC crate that is getting close to stabilizing. I am currently using capnproto-rust in one of my projects for the same thing. It's more difficult to get spun up on it relative to Go and gRPC but I like the idea more.
Ed Lewis
@ninjabear
Feb 01 2017 16:34
ah cool! thanks for the info
salpalvv
@salpalvv
Feb 01 2017 16:34
capnp-rpc-rust is the RPC crate.
Michal 'vorner' Vaner
@vorner
Feb 01 2017 17:08
This is stupid. I had to return to some of my a bit older C++ code. And now whenever I find a bug I think „Crap, why didn't the compiler tell me this is wrong?“
Sasha Hilton
@sashahilton00
Feb 01 2017 19:52
evening all, I was hoping that someone could enlighten me as to how one could go about internally restarting a rust program. Ideally what would happen is that when the rust program receives a restart IPC message, it restarts itself. Is there any way to do this from within the program itself, or are we forced to use an external helper program to do this?
Robyn Speer
@rspeer
Feb 01 2017 20:28
Not an expert, but it seems like this shouldn't require anything special. There's no interpreter involved in running Rust code, and any global state that exists is something you put there. So you should be able to write code that returns the program state to what it was when your program started, right?
In other languages that could be complicated by global effects that are hard to control, particularly memory leaks, but you shouldn't have those in safe Rust code.
Peter Atashian
@retep998
Feb 01 2017 20:31
@sashahilton00 You can always just have your program spawn a new instance of itself and kill the current instance.
Sasha Hilton
@sashahilton00
Feb 01 2017 20:35
in thoery yes, that would be a perfectly good way to do it, though the way the program has been written up until now has not been architected for resetting state to it’s starting form, and furthermore integrates with a C based program that stores it’s own state that only gets cleared on a restart. Hence in a rewrite one would go down the route you mentiion. @retep998 could you shed some light on how a program might go about spawning a new instance of itself then clean up the old one? Thanks
Peter Atashian
@retep998
Feb 01 2017 20:36
Just use Command to spawn a new process, you can also grab the arguments from std::env::args_os to ensure it is spawned the same way. Then you just exit the current process.
Sasha Hilton
@sashahilton00
Feb 01 2017 20:36
interesting. will give that a go. Thanks.
Sergey Noskov
@Albibek
Feb 01 2017 20:39
also there is exec system call if you are on unix and choose to select the complete restart
Sasha Hilton
@sashahilton00
Feb 01 2017 20:40
i know about the /proc/self/exe on linux, the problem is it has to be cross compatible :( otherwise I’d just use that
salpalvv
@salpalvv
Feb 01 2017 22:02
I'm attempting to translate some c++ to rust and I am at a loss.
The c++ code creates an array of function pointers void * (**funcs)(...);
Then, it calls a COM function ComFunc with funcs as an argument cast as an array of unsigned long pointers com_obj->ComFunc((unsigned long**)&funcs);
This is to fill funcs with functions so as to be called with constant offsets funcs[OFFSET_VAL](args);
I don't care about safety because it's COM but I just don't know how this would be expressed in rust.
Alexander Ronald Altman
@pthariensflame
Feb 01 2017 23:03
@salpalvv The following code should behave identically to your example:
extern crate libc;

// the user code you're looking for
unsafe fn call_com() {
    com_func((&mut fns.as_mut_ptr()) as *mut _ as *mut _) // double cast necessary for type checker's sake here
}

// imitation of the com API in question
extern "stdcall" { fn com_func(fns: *mut *mut libc::c_ulong); }
You can try to use https://docs.rs/com-rs if you want a better interface.
Alexander Ronald Altman
@pthariensflame
Feb 01 2017 23:15
Sorry, let me correct that code:
extern crate libc;
use std::mem;

// the user code you're looking for
unsafe fn call_com() {
    let fns: &mut [unsafe extern "stdcall" fn(/* function pointer argument types go here */) -> /* function pointer return type goes here */]
        = [mem::zeroed(); /* number of functions in array goes here */];
    com_func((&mut fns.as_mut_ptr()) as *mut _ as *mut _) // double cast necessary for type checker's sake here
    // use array of functions here
}

// imitation of the com API in question
extern "stdcall" { fn com_func(fns: *mut *mut libc::c_ulong); }
Tim
@tikue
Feb 01 2017 23:16
does anyone know of any open issues related to "undefined reference" occurring when using impl Trait?
I only see a closed issue
Alexander Ronald Altman
@pthariensflame
Feb 01 2017 23:17
@tikue Not sure; what’s your code?
Tim
@tikue
Feb 01 2017 23:18
@pthariensflame my code is a library with one use of impl Trait, and the "undefined reference" occurs in someone else's private repo when using my crate. I can't reproduce it, which is why I'm wondering about any existing open issues
Alexander Ronald Altman
@pthariensflame
Feb 01 2017 23:18
Huh. I’ve never had anything like that happen, but I would report it on github at rust-lang/rust.
Tim
@tikue
Feb 01 2017 23:18
it looks like rust-lang/rust#38226
Alexander Ronald Altman
@pthariensflame
Feb 01 2017 23:18
It sounds like an ICE (or similar) to me.
Tim
@tikue
Feb 01 2017 23:18
it doesn't occur when compiling but at runtime
Alexander Ronald Altman
@pthariensflame
Feb 01 2017 23:19
Oh, I see.
Well, that issue had a problem at compile time, so I think it’s unrelated.
Tim
@tikue
Feb 01 2017 23:20
yeah
the error looks the same though
Alexander Ronald Altman
@pthariensflame
Feb 01 2017 23:21
Hm.
Can you ask the other person if they’re using any extern blocks?
That would be my first instict to check.
It sounds like the kind of thing that’s caused by platform incompatibilities.
Tim
@tikue
Feb 01 2017 23:23
I'll try to find out
salpalvv
@salpalvv
Feb 01 2017 23:50
@pthariensflame Thanks for the awesome example. I'm working through it now.