These are chat archives for rust-lang/rust

21st
Jan 2019
David O'Connor
@David-OConnor
Jan 21 00:36
Hey dudes - is there a way to use proc macros (Or something else?) To decorate a func so it could return either a single item, or a tuple? Trying to set up an API that in most cases returns a single item, but sometimes returns a tuple, without forcing the user to always return a tuple. This would be to create a cleaner API. Unfortunately, it looks like proc_macros are mostly undocumented
This message was deleted
matrixbot
@matrixbot
Jan 21 02:28
bspeice What you're talking about sounds like returning an enum of either single or tuple. Alternately, one item in the tuple could be Option. Why are you thinking that proc_macros would be the right way to do this?
Kelly Thomas Kline
@kellytk
Jan 21 03:19
Why did Mozilla stop working on project Mentat? It seems like useful software
Kelly Thomas Kline
@kellytk
Jan 21 03:26
Which Rust-based distributed data store, key value or SQL, would you recommend for a p2p app where I need to static link it in the node binary and not run as a separate server like PostgreSQL would be?
matrixbot
@matrixbot
Jan 21 03:30
bspeice If you're already in Node, would libp2p work?
Kelly Thomas Kline
@kellytk
Jan 21 03:30
bspeice Actual node, not the confusingly named software :-)
matrixbot
@matrixbot
Jan 21 03:31
bspeice Cool. Then do you need truly static linking? If not, my first thought would be to check out the bindings for leveldb, but that's not going to get you "distributed."
bspeice Otherwise, contributing to the Rust implementation for libp2p might be the way to go anyway.
Kelly Thomas Kline
@kellytk
Jan 21 03:33
Reading now, thanks bspeice
thojest
@thojest
Jan 21 11:14
somebody here using intelliJ Rust plugin?
is it possible to configure the default build process?
toxicafunk
@toxicafunk
Jan 21 11:29
wdym by configure?
You can edit the Run configurations which might be what u need
thojest
@thojest
Jan 21 11:35
@toxicafunk yep did that. thx
David Holroyd
@dholroyd
Jan 21 11:46
anyone happen to know how to build an app with the zmq crate, also having libzmqbuilt in statically, rather than depending on the system-installed version?
David Holroyd
@dholroyd
Jan 21 11:51
...or can suggest an alternative (rust native?) crate for supporting one-way message passing on localhost that's tolerant of either sending or receiving process failures, making 'best efforts' to get messages though
(bonus points if solution also works from Python!)
David Holroyd
@dholroyd
Jan 21 12:11
hmm.. wonder if UDP packets would be large enough since it's localhost only...
thojest
@thojest
Jan 21 12:46
what would you recommend for simple http requests?
reqwest?
im operating an AWS lambda which should make a http request when being called
toxicafunk
@toxicafunk
Jan 21 12:56
i settled for reqwest but am open for suggestons if anyone have any
thojest
@thojest
Jan 21 13:02
one more question: when defining trait bounds, what is the correct way in current Rust
using impl keyword or <T: MyTrait>
is there any difference?
Tim Robinson
@1tgr
Jan 21 13:12
With <T: MyTrait>, the caller decides the actual type. The function has to deal with any type T, and all it knows about T is it implements MyTrait
With impl MyTrait, the function decides the actual type. The caller has to deal with any type, and all it knows about that type is it implements MyTrait
In return position, that is
In argument position something like fn f(g: impl MyTrait) is arguably easier to read than fn f<T: MyTrait>(g: T)
Victor Lopes
@vlopes11
Jan 21 14:49
Hello rustaceans, good afternoon. When I create a crate with a dependency that is a dylib, the compiler will embed that library into the created binary, generating a single executable file. I'd like the compiler to not do that. To, instead, generate a .so file, and a binary executable that will dynamically load that dependency. I checked the compiler documentation, and didn't find this. It's naturally easy to create the .so with the crate-type dylib when we are compiling the lib, but the executable will not load the shared object. Is it possible?
thojest
@thojest
Jan 21 14:52
thx @1tgr
Denis Lisov
@tanriol
Jan 21 15:15
@vlopes11 You do understand that you cannot use, for example, generics across a .so boundary, I hope?
You need to add -C prefer-dynamic to rustc arguments, AFAIK.
Victor Lopes
@vlopes11
Jan 21 16:50
@tanriol Yep, absolutely clear. Thanks man. The idea is to share some atomic native types only
thojest
@thojest
Jan 21 17:31
how on earth do I "unwrap" a future?
let mut req_map = HashMap::new();
    req_map.insert("secret", CAPTCHA_SECRET);
    req_map.insert("response", user_token);
    client
        .post(CAPTCHA_BACKEND)
        .json(&req_map)
        .send()
        .and_then(|mut res| res.json())
do I have to call poll
?
Denis Lisov
@tanriol
Jan 21 17:38
Normally you don't "unwrap" it, just chain your actions to the end of the combinator chain.
thojest
@thojest
Jan 21 17:38
ok so I think I understand now
and_then ~ mergeMap
then ~ subscribe
like in rxjs for example
Denis Lisov
@tanriol
Jan 21 17:40
Heard about the Rx family a few times, but no experience.
thojest
@thojest
Jan 21 17:46
hmm can you give me an example
what am I doing wrong here
#[derive(Serialize, Deserialize, Debug)]
pub struct CaptchaResponse {
    success: bool,
    challenge_ts: String, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
    hostname: String,     // the hostname of the site where the reCAPTCHA was solved
}

pub fn get_captcha_result(user_token: &str) -> CaptchaResponse {
    // TODO: Add remoteip to request
    let mut req_map = HashMap::new();
    req_map.insert("secret", CAPTCHA_SECRET);
    req_map.insert("response", user_token);
    client
        .post(CAPTCHA_BACKEND)
        .json(&req_map)
        .send()
        .then(|mut res| {
            res.expect("Unable to deserialize Response")
                .json::<CaptchaResponse>()
        })
}
expected type captcha::CaptchaResponse found type futures::Then<reqwest::async_impl::client::Pending, reqwest::async_impl::response::Json<captcha::CaptchaResponse>
so I am returning the wrong type
so I guess the idea is that you should return futures::Then<....>
thojest
@thojest
Jan 21 17:51

pub fn get_captcha_result(user_token: &str) -> impl Future {
    // TODO: Add remoteip to request
    let mut req_map = HashMap::new();
    req_map.insert("secret", CAPTCHA_SECRET);
    req_map.insert("response", user_token);
    client
        .post(CAPTCHA_BACKEND)
        .json(&req_map)
        .send()
        .then(|res| {
            res.expect("Unable to deserialize Response")
                .json::<CaptchaResponse>()
        })
}
thojest
@thojest
Jan 21 17:57
ok I guess I should read a bit on Futures and Tokio :)
John
@onFireForGod_gitlab
Jan 21 18:58
-> impl Future<item=ResponseFuture, Error=hyper:Error>
what framework are you using
also might want to save the future in a Box
so you can poll it later
or pass it directly into a runtime
thojest
@thojest
Jan 21 21:47
@onFireForGod_gitlab thx, got it working now. im using reqwest