These are chat archives for rust-lang/rust

16th
Nov 2017
Moggers
@Moggers
Nov 16 2017 05:13
@cengizIO I might be able to replicate it, I was mangling some code trying to fix clippy warnings
I caused it when moving braces and stuff around when replacing a match with an if else
Abhi
@abhishek737
Nov 16 2017 05:39
I am planning to learn rust, what is the best way to start it, it's official docs or any text book
Ilya Bogdanov
@vitvakatu
Nov 16 2017 06:24
@abhishek737 hello! You should definitely start from the official book doc.rust-lang.org (sorry, I'm from phone, can't get the whole link)
Marcel
@marcelbuesing
Nov 16 2017 06:43
@abhishek737 I'd recommend the official docs https://doc.rust-lang.org/book/first-edition/getting-started.html
Abhi
@abhishek737
Nov 16 2017 06:48
Thanks @marcelbuesing @vitvakatu
Raunak Ramakrishnan
@rrampage
Nov 16 2017 14:14
Hi all. I am new to rust. I am trying to create a library. I have a src/lib.rs in which I have another module declared as pub mod a. The code for module a is in src/a.rs. a.rs contains a struct and an Impl. I also have a mod tests in lib.rs for testing. In there, I am not able to use things from mod a. I have put pub in front of everything in mod a
Aleksey Kladov
@matklad
Nov 16 2017 14:15
Do you have use super::* in your test mod?
Raunak Ramakrishnan
@rrampage
Nov 16 2017 14:15
no
I have a use mod a in tests
Aleksey Kladov
@matklad
Nov 16 2017 14:16
use mod a is invalid syntax thoguh
Raunak Ramakrishnan
@rrampage
Nov 16 2017 14:17
ok. what should I use instead of that?
Raunak Ramakrishnan
@rrampage
Nov 16 2017 14:28
it works if all code is in lib.rs but if I replace the pub mod a {.. } with pub mod a and the a.rs file, it gives a compile error
Aleksey Kladov
@matklad
Nov 16 2017 14:29
Hm, mod a { .. } and mod a; + a.rs are equivalent. What is the text of the error?
Raunak Ramakrishnan
@rrampage
Nov 16 2017 14:31
Could not find OpCode in a
OpCode is struct name
Aleksey Kladov
@matklad
Nov 16 2017 14:32
Hm, that means that a.rs does not contain OpCode at all. So, you have src/lib.rs and src/a.rs? And mod a; is declared on the top level of lib.rs? And a.rsfile is saved to disk?
Raunak Ramakrishnan
@rrampage
Nov 16 2017 14:33
yes
when I copy the code from a.rs to lib.rs in pub mod, it works
I'll just check if I am doing anything else wrong
Ilya Bogdanov
@vitvakatu
Nov 16 2017 14:37
Is OpCode marked with pub?
Raunak Ramakrishnan
@rrampage
Nov 16 2017 14:37
yes
Ilya Bogdanov
@vitvakatu
Nov 16 2017 14:40
you need to use a::OpCode I suppose
or import it as "use a::OpCode"
It works when I copy paste to lib.rs ... but same thing in another file, it fails saying not found
I have checked that there is no problem in filename / permissions
Raunak Ramakrishnan
@rrampage
Nov 16 2017 15:15
got it... it was because I was having pub mod x... in x.rs
Towaha
@SOFTowaha
Nov 16 2017 15:17
Anyone can help me with a websocket code?
Sherab Giovannini
@Shaddy
Nov 16 2017 15:25

guys I have an structure like this

first_module/
    mod.rs (doing mod file.rs for each mod)
    sample.rs
    first_place.rs
second_module/
    mod.rs
    second_place.rs
main.rs

How could I use anything defined at first_place, at second_place?

apparently, mod doesn't works, also extern crate doesn't
Raunak Ramakrishnan
@rrampage
Nov 16 2017 15:29
you can try use super::first_module::first_place
Sherab Giovannini
@Shaddy
Nov 16 2017 15:29
nevermind, I guess that i found a workaround
Sherab Giovannini
@Shaddy
Nov 16 2017 16:33
well, to solve my stuff just if anyone has that kind of problem: Just put as many mods as you want, but if you have main.rs, put all your #[macro_use] and so on there, if you have also a lib.rs, then use lib.rs to connect them and extern crate into your main.
Emil Gardström
@Emilgardis
Nov 16 2017 21:04
I've just submitted a cc to a video on the Rust yt channel, and I thought it would be pretty nice to actually try to have closed captions on all those videos. What do you think about this?