These are chat archives for rust-lang/rust

7th
Jun 2018
Carl Dong
@dongcarl
Jun 07 2018 03:28
Hi all, how can I make an enum of either: std::ops::Range and std::ops::RangeFrom?
Paul Masurel
@fulmicoton
Jun 07 2018 03:29

Range { start: 0, end: 3 }

should work

Carl Dong
@dongcarl
Jun 07 2018 03:29
@fulmicoton I'm thinking something like:
enum MyRange {
    Range,
    RangeFrom,
}
Paul Masurel
@fulmicoton
Jun 07 2018 03:30
Sorry misunderstood your question
Carl Dong
@dongcarl
Jun 07 2018 03:30
But obviously that doesn't work
So I'm wondering how I might do that
Paul Masurel
@fulmicoton
Jun 07 2018 03:30
I think there is an API with the notion of Boundary
it might be in nightly though
Carl Dong
@dongcarl
Jun 07 2018 03:31
Well I'm wondering how I might do that in the normal sense
As in an enum that's either Range or RangeFrom
(trying to use stable haha)
Paul Masurel
@fulmicoton
Jun 07 2018 03:33
I should probably stop putting my foot in my mouth :D
Carl Dong
@dongcarl
Jun 07 2018 03:34
This seems to work:
enum DecimalRange {
    DecimalRangeBoth(std::ops::Range<Decimal>),
    DecimalRangeFrom(std::ops::RangeFrom<Decimal>),
}
Carl Dong
@dongcarl
Jun 07 2018 05:07
How do I use an experimental API given that I've installed and defaulted to nightly?
Dylan DPC
@Dylan-DPC
Jun 07 2018 06:46
@dongcarl you should be able to use it
Paul Masurel
@fulmicoton
Jun 07 2018 06:47
write code that uses it. The compiler will complain and tell you the name of the missing feature . Add #[feature(THENAMEOFTHEFEATURE)] in you lib.rs
trsh
@trsh
Jun 07 2018 07:37
Hi guys! What would be the equivalent for C++ std::map in rust? for binding Extern C++
Michal 'vorner' Vaner
@vorner
Jun 07 2018 08:11
Functional-wise BTreeMap. But if you want to use one data structure in both C++ and Rust, then you have to wrap one to the other somehow. You can't just pass a pointer to one, type-cast it to the other and expect it to work.
trsh
@trsh
Jun 07 2018 08:15
@vorner clear, suspected so
Michal 'vorner' Vaner
@vorner
Jun 07 2018 08:16
There are some tools to help with creating the bindings in both ways. Bindgen should work C/C++ → Rust. I don't remember the name for the other direction, but it exists.
trsh
@trsh
Jun 07 2018 08:18
Bindgen works fine With C
And doesn't work with advanced c++
In my example it just dies on 'nemaspace'
Michal 'vorner' Vaner
@vorner
Jun 07 2018 08:24
There are some things you can tweak in the config, maybe that helps.
Or you can do a double-layered approach. Thinner wrapper in C/C++, you bundle that C++ file and generate bindings for that.
I found it can save a lot of work, to make the C++ API „sane“ for bindgen to work.
trsh
@trsh
Jun 07 2018 08:28
Good idea. Btw hat is best option for array type to bind to C/C++?
Pointers?
Michal 'vorner' Vaner
@vorner
Jun 07 2018 08:31
Pointer & length is probably a good option, but you have to be careful (for example, there's a method on slice to get the pointer, casting the &[T] won't work).
trsh
@trsh
Jun 07 2018 08:41
Meh. C works more naturally with Rust, because fewer features
Sylwester Rąpała
@xoac
Jun 07 2018 09:02
Is there a way to easy find depending crates for my project? I have a lot of things like:
   Compiling itoa v0.3.4
   Compiling itoa v0.4.1
   Compiling log v0.3.9
   Compiling log v0.4.1
   Compiling crossbeam-utils v0.3.2
   Compiling crossbeam-utils v0.2.2
I would like to do some PR if possible to use never version
Michal 'vorner' Vaner
@vorner
Jun 07 2018 09:03
Something like cargo-tree could help
Sylwester Rąpała
@xoac
Jun 07 2018 09:04
Thx <3
Andrey Lesnikov
@ozkriff
Jun 07 2018 09:07
though it may be very hard to update some common crates :( - reem/rust-ordered-float#37
Dylan DPC
@Dylan-DPC
Jun 07 2018 11:44
@xoac alternatively, you can check the crate on crates.io and check the dependant crate
Sylwester Rąpała
@xoac
Jun 07 2018 12:20
cargo tree is good :)
trsh
@trsh
Jun 07 2018 17:03
Hey guys! I must call a function dependent on a value in json returned from remote. What is my best bet? A simple match ?
Zakarum
@omni-viral
Jun 07 2018 17:43
Correct
VJ
@00imvj00
Jun 07 2018 18:38
 fn stream<
        'l,
        S: Stream<Item = Packet, Error = io::Error> + 'l,
        SS: Sink<SinkItem = Packet, SinkError = io::Error> + 'l,
    >(
        rx: S,
        tx: SS,
    ) -> impl Future<Item = (), Error = io::Error> + 'l {
        rx.forward(tx).then(|_| Ok::<(), io::Error>(()))
    }

let s_receiver = Self::socket_loop::<'p>(rx, &mut self.state);
Above example throws warning, <'p> is not allowed or something, can any body confirm if this is the right way to pass lifetime ?
VJ
@00imvj00
Jun 07 2018 19:27
how static variables are dropped ?
Zakarum
@omni-viral
Jun 07 2018 20:09
@00imvj00 did you mean Self::stream or something?
@00imvj00 AFAIK static variables are dropped after main is finished
sitty
@sitty
Jun 07 2018 20:26
is there a lib for kerberos authentication?
not native but existing binding
Fredrik Portström
@portstrom
Jun 07 2018 21:14

Is there a way to make a macro that constructs multiple patterns for a match expression? Any way is fine, whether it's joining them with | or with ,, and whether the macro is applied within a match expression or the macro constructs the entire match expression. I don't find anything that works.

To give an example, I have match expressions that look like:

match title {
    "citoslovce" | "citoslovce (1)" | "citoslovce (2)" | "citoslovce (3)" | "citoslovce (4)" | "citoslovce (5)" => example(1),
    "idiom" | "idiom (1)" | "idiom (2)" | "idiom (3)" | "idiom (4)" | "idiom (5)" => example(2),
    "podstatné jméno" | "podstatné jméno (1)" | "podstatné jméno (2)" | "podstatné jméno (3)" | "podstatné jméno (4)" | "podstatné jméno (5)" => example(3),
    "předložka" | "předložka (1)" | "předložka (2)" | "předložka (3)" |"předložka (4)" | "předložka (5)" => example(4),
    "předpona" | "předpona (1)" | "předpona (2)" | "předpona (3)" | "předpona (4)" | "předpona (5)" => example(5),
    "přídavné jméno" | "přídavné jméno (1)" | "přídavné jméno (2)" | "přídavné jméno (3)" | "přídavné jméno (4)" | "přídavné jméno (5)" => example(6),
    "přípona" | "přípona (1)" | "přípona (2)" | "přípona (3)" | "přípona (4)" | "přípona (5)" => example(7),
    "příslovce" | "příslovce (1)" | "příslovce (2)" | "příslovce (3)" | "příslovce (4)" | "příslovce (5)" => example(8),
    "přísloví" | "přísloví (1)" | "přísloví (2)" | "přísloví (3)" | "přísloví (4)" | "přísloví (5)" => example(9),
    "rčení" | "rčení (1)" | "rčení (2)" | "rčení (3)" | "rčení (4)" | "rčení (5)" => example(10),
    "sloveso" | "sloveso (1)" | "sloveso (2)" | "sloveso (3)" | "sloveso (4)" | "sloveso (5)" => example(11),
    "slovní spojení" | "slovní spojení (1)" | "slovní spojení (2)" | "slovní spojení (3)" | "slovní spojení (4)" | "slovní spojení (5)" => example(12),
    "spojka" | "spojka (1)" | "spojka (2)" | "spojka (3)" | "spojka (4)" | "spojka (5)" => example(13),
    "zkratka" | "zkratka (1)" | "zkratka (2)" | "zkratka (3)" | "zkratka (4)" | "zkratka (5)" => example(14),
    "zájmeno" | "zájmeno (1)" | "zájmeno (2)" | "zájmeno (3)" | "zájmeno (4)" | "zájmeno (5)" => example(15),
    "částice" | "částice (1)" | "částice (2)" | "částice (3)" | "částice (4)" | "částice (5)" => example(16),
    "číslovka" | "číslovka (1)" | "číslovka (2)" | "číslovka (3)" | "číslovka (4)" | "číslovka (5)" => example(17)
    _ => 0
}

It would be nice to be able to just give only the first title of each branch and have the others generated.

I put the example in the playground in case someone wants to play with it: http://play.rust-lang.org/?gist=e2a8f07b8ddbe88f4e934bafb60db7d7

Fredrik Portström
@portstrom
Jun 07 2018 22:22

I found the trick that lets me make a DSL around match expressions: https://danielkeep.github.io/tlborm/book/pat-push-down-accumulation.html

Here's the updated code: http://play.rust-lang.org/?gist=9ca76376087a0a852cf678d931c62dfb

VJ
@00imvj00
Jun 07 2018 23:55
@omni-viral yes. sorry for mis spelling , so how would i pass on parent function's named lifetime to other function ?