These are chat archives for rust-lang/rust

16th
Oct 2018
John
@gitlabaccount624_gitlab
Oct 16 2018 02:18
hi is there a way to have a global hashmap for my program that a bunch of functions can update?
i wanna make a token bucket for my app server
so it'd be userid -> { tokenCount, timestamp } i guess. can i use CAS or something so i dont need locks?
Vitaly
@Virtuos86
Oct 16 2018 02:38
@jonathansty You could use a some zero sized type as a possible workaround: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=ae774ad025f28cbd6e779f74e1619f4a
There is no memory overhead.
Krzysztof Woś
@krzysztofwos
Oct 16 2018 13:50
Folks, is it appropriate to mention a company that is looking to hire Rust developers here? Seems like a good place to find the right people, but I'm weary of any sort of advertising spoiling technical discussions
Michal 'vorner' Vaner
@vorner
Oct 16 2018 13:51
Probably fine if there's not too much of it. Also, https://this-week-in-rust.org/ has a section for Rust jobs.
Krzysztof Woś
@krzysztofwos
Oct 16 2018 13:53
Alright, so here's the shameless plug: https://jobs.lever.co/binance/2c03bc65-3c1a-43d8-ab2c-bbf5899c9d4a
Thanks for the pointer, I'll post something there as well
Victor Moroz
@vmoroz_gitlab
Oct 16 2018 15:21

Can somebody help me with un-boxing:

enum List <'a> {
    Cons(i32, &'a Box<List<'a>>),
    Nil,
}

use List::{Cons, Nil};

fn main() {
    let nil = Box::new(Nil);
    let l10 = Box::new(Cons(10, &nil));
    if let Cons(n, _) = l10 {
      println!("{:?}", n);
    }
}

  --> src/main.rs:11:12
   |
11 |     if let Cons(n, _) = l10 {
   |            ^^^^^^^^^^ expected struct `std::boxed::Box`, found enum `List`
   |
   = note: expected type `std::boxed::Box<List<'_>>`
              found type `List<'_>`

Is there a way to extract Cons (or any other enum) out of Box with stable Rust (I'm aware of box keyword, it's not in stable yet)?

Vitaly
@Virtuos86
Oct 16 2018 15:32
if let Cons(n, _) = *l10?
Victor Moroz
@vmoroz_gitlab
Oct 16 2018 15:50
@Virtuos86 Thanks! I was sure I tried it, apparently I didn't :( I stumbled on a nested if let (not in this code) where, as I see now, I have to use **tail as the first match Cons(n, tail) returns a reference to Box.
Victor Lopes
@vlopes11
Oct 16 2018 20:32
Rustacens, Tokio is still the strong call for async IO or do we have a more interesting option available?