These are chat archives for rust-lang/rust

6th
Mar 2018
Josh
@joshlemer
Mar 06 2018 03:24

Hey I have a question, if I want to make a new hashmap by explicitly specifying thee type parameters but not by using inference, how can I do that?
I try to do:

HashMap<i32, String>::new()
HashMap::<i32, String>new();
HashMap::new<i32, String>();

but none of the 3 work

Josh
@joshlemer
Mar 06 2018 03:29

woah turns out this is how

HashMap::<i32, String>::new()

cheers!

Hans W. Uhlig
@huhlig
Mar 06 2018 03:42
hmm... stupid question. can you serialize a function pointer?
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 06 2018 05:22
@huhlig I'd be interested what #[derive(Debug)] would do for a function? maybe it would let you print it?
^also noob
mnivoliez
@mnivoliez
Mar 06 2018 06:21
Guys, I have write an article about ownership, borrow and lifetime. I was wondering if I said something false. Can someone check it out? https://www.mathieu-nivoliez.com/posts/2018-03-05-getting-started-with-rust-reference-and-lifetime.html
But it was funny to ask :)
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 06 2018 06:25
:(
Sarp Güney Başaraner
@sgbasaraner
Mar 06 2018 06:49
Hey, I have a potentially quick question: are UdpSocket sockets cross-platform?
Sarp Güney Başaraner
@sgbasaraner
Mar 06 2018 07:09
Arthur
@Biacode
Mar 06 2018 07:36
Hey everyone, not writing code in rust for a while. Is there any new books or a new way to learn / remember the language? Or I should use official documentation and rustbyexample like before? Thanks.
Christian Witts
@ChristianWitts
Mar 06 2018 08:36
http://shop.oreilly.com/product/0636920040385.do is the latest book, outside of the https://doc.rust-lang.org/book/ which has an in progress second edition rewrite
Tropic
@TropicSapling
Mar 06 2018 09:29
@RReverser Ok, I was just asking because my code would look a bit better if I didn't need to have the variables outside. The code still works just fine though so I'll see if I can find some other way of making the code more organised and less messy :)
Matteo Ferretti
@ZER0
Mar 06 2018 10:09
Hi there! Is there any way to link unused function and module? I tried -C link-dead-code but doesn't seems to work – I'm targetting wasm32-unknown-unknown.
Michal 'vorner' Vaner
@vorner
Mar 06 2018 10:23
Are the functions public?
Matteo Ferretti
@ZER0
Mar 06 2018 10:31
yes, so to be precise: let's say I have the classic pub extern fn malloc that you see in a lot of demos for rust / wasm. This method is actually used only from JS side not Rust, it's just exported from Rust. Everything works fine if I have this function in the main src/lib.rs itself; but if I move it to another rust module it become undefinedon JS side. That's because for the compiler, I guess, it's an unused module. In fact, it's linked if I actually call it from src/lib.rs.
Even if the definition is in another rust model.
*module
Michal 'vorner' Vaner
@vorner
Mar 06 2018 10:32
Is the module also public?
Matteo Ferretti
@ZER0
Mar 06 2018 10:36
In src/lib I declared pub mod memory (memory is the name of the module where malloc is)
Matteo Ferretti
@ZER0
Mar 06 2018 10:48
@vorner okay, my bad: my last tests where all wrongs since the browser was using the wrong compiled wasm -_- my apologies! Indeed pub mod was working.
TatriX
@TatriX
Mar 06 2018 12:31
What is a best tool to profile rust code today?
(linux)
Aleksey Kladov
@matklad
Mar 06 2018 13:00
TatriX
@TatriX
Mar 06 2018 13:03
Cool, thanks!
TatriX
@TatriX
Mar 06 2018 13:09
And what about pperf+cpuprofile?
Aleksey Kladov
@matklad
Mar 06 2018 13:11
Haven't heard about cpuprofile before, so don't know, but sounds very intriguing (if this is about https://www.npmjs.com/package/perf-cpuprofile).
If one is used to pperf (maybe from the golang) it looks quite nice.
apiraino
@apiraino
Mar 06 2018 15:23
Hello, I've just discovered that the email announcing the upcoming RustFest in Paris was in my spam folder since +2 weeks
Did anyone had this problem, too? Just asking...
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 06 2018 20:55
ok, so why does any and all mutably borrow? https://doc.rust-lang.org/core/iter/trait.Iterator.html#method.any
I don't get it, and when I just want to immutably scan an iterable with some predicate, I can't do it. I have to make it mutable, if I have more than one predicate then I just can't do it <:(
Ghoughpteighbteau
@Ghoughpteighbteau
Mar 06 2018 21:01
wait, just figured it out, it's because you're mutating the iterator
if I just clone the iterator then that's fine.
I think. that doesn't deep copy the iterators target does it? O.o
Dylan DPC
@Dylan-DPC
Mar 06 2018 21:45
how do you guys handle generics for a function? I have a function with the signature S pub fn some_foo<T>(foo: T) which creates another structure Bar { b: foo}
but i get an error that type of b is T instead of what i'm passing in foo
Dylan DPC
@Dylan-DPC
Mar 06 2018 21:51
i'm calling it normally, such as some_foo(value)
the argument isn't of the same "type" so i can't do something like Vec<T> (i could Box it though)
Dylan DPC
@Dylan-DPC
Mar 06 2018 21:56
thanks. so i will have to wrap Bar with generics?
ousado
@ousado
Mar 06 2018 21:58
I'm not sure what you're trying to do, so "maybe"
Dylan DPC
@Dylan-DPC
Mar 06 2018 22:03
the thing is i have some_foo in a trait. and each implementation will return a seperate struct type. So having generics on the struct is overkill for me
though i could work around with it to obey the generics. Will try it tomorrow. Thanks :)
ousado
@ousado
Mar 06 2018 22:05
how about a minimal example that demonstrates the issue?
Dylan DPC
@Dylan-DPC
Mar 06 2018 22:07
too much code to type :P
will try an example tomorrow and post it here :)