These are chat archives for rust-lang/rust

15th
Aug 2016
Andrey Lesnikov
@ozkriff
Aug 15 2016 06:15
Andrey Ivanov
@a-nigredo
Aug 15 2016 10:09

hi all, I'm using manual(https://doc.rust-lang.org/book) for studying rust but I'm stuck on https://doc.rust-lang.org/book/crates-and-modules.html#exporting-a-public-interface. It doesnt compile with message:


   Compiling phrases v0.1.0 (file:///D:/rust/phrases)
src\main.rs:7:38: 7:54 error: unresolved name `greetings::hello` [E0425]
src\main.rs:7     println!("Hello in English: {}", greetings::hello());
                                                   ^~~~~~~~~~~~~~~~
<std macros>:2:27: 2:58 note: in this expansion of format_args!
<std macros>:3:1: 3:54 note: in this expansion of print! (defined in <std macros>)
src\main.rs:7:5: 7:58 note: in this expansion of println! (defined in <std macros>)
src\main.rs:7:38: 7:54 help: run `rustc --explain E0425` to see a detailed explanation
src\main.rs:8:40: 8:58 error: unresolved name `farewells::goodbye` [E0425]
src\main.rs:8     println!("Goodbye in English: {}", farewells::goodbye());
                                                     ^~~~~~~~~~~~~~~~~~
<std macros>:2:27: 2:58 note: in this expansion of format_args!
<std macros>:3:1: 3:54 note: in this expansion of print! (defined in <std macros>)
src\main.rs:8:5: 8:62 note: in this expansion of println! (defined in <std macros>)
src\main.rs:8:40: 8:58 help: run `rustc --explain E0425` to see a detailed explanation
error: aborting due to 2 previous errors
error: Could not compile `phrases`.

is it an error in manual or I'm doing something wrong?

Lilian Anatolie Moraru
@lilianmoraru
Aug 15 2016 10:19
You probably copied the text without the previous statements
You can press on the website(go with the mouse over the code in the website) on the "Run" button. It will open up the playground with all the code that is needed to compile
For demonstration purposes the code is cut in smaller pieces, so if you take a small piece, it won't compile by itself.
If the modules are internal, than you are probably missing
mod greetings;
mod farewells;
Andrey Ivanov
@a-nigredo
Aug 15 2016 10:24
@lilianmoraru ok, ty, I'll try
Lilian Anatolie Moraru
@lilianmoraru
Aug 15 2016 10:24
Ok, I see the example is using a crate that you probably created before that(I have not re-read The Book for a long time and I think this example changed)
No, to solve your problem you need to go through all the next steps the example mentiones
And then compile
If you are still blocked, put it on a pastebin or https://gist.github.com/
Andrey Ivanov
@a-nigredo
Aug 15 2016 10:26
ok
Lilian Anatolie Moraru
@lilianmoraru
Aug 15 2016 10:26
the code*
Zakarum
@omni-viral
Aug 15 2016 15:34

Why there is an error?

trait X {
    fn into_trait(&self) -> &X { self }
}

Compiler says I have to add Self: Sized. What for?

Sergey Noskov
@Albibek
Aug 15 2016 15:36
You can only return values which size is known at compile time.
Zakarum
@omni-viral
Aug 15 2016 15:36
I return reference
It always has known size
Thomas Koehler
@Bastacyclop
Aug 15 2016 15:39
probably because it doesn't know wether the reference is fat or not ?
Andrii
@j2ko
Aug 15 2016 15:40
struct X {}
impl X {
    fn into_trait(&self) -> &X { self }
}
Zakarum
@omni-viral
Aug 15 2016 15:48
@j2ko <thumb-up> But this is not what I need.
@Albibek I understood.
Also I can't declare trait X: Sized {...}. and make trait-objects &X
I found one solution. I'll implement this function in trait implementations. Where I would know that Self: Sized. And I would use it for conversion.
Zakarum
@omni-viral
Aug 15 2016 15:50
@j2ko I need to get trait-object. Not &Self
Thomas Koehler
@Bastacyclop
Aug 15 2016 15:52
trait X {
    fn into_trait(&self) -> &X where Self: Sized { self }
}
is this not enough ?
Zakarum
@omni-viral
Aug 15 2016 15:55
I can't add Self: Sized. Because I want to call this function via trait-object.
Thomas Koehler
@Bastacyclop
Aug 15 2016 15:56
so you have a trait object Y (object pointer + virtual table for Y) and you want to get a trait object X (object pointer + virtual table for X) ?
Zakarum
@omni-viral
Aug 15 2016 15:57
Yeap.
But X equals Y
Thomas Koehler
@Bastacyclop
Aug 15 2016 15:57
what's the point if they are equal ?
Zakarum
@omni-viral
Aug 15 2016 15:59
I have heterogeneous tree structure
trait TreeNode {
    fn find(&'a self, some_stuff_to_find_right_node) -> Option<&'a TreeNode>
}
Here TreeNode contains other TreeNodes. Which can have different type
Thomas Koehler
@Bastacyclop
Aug 15 2016 16:04
trait TreeNode {
    fn find(&self) -> Option<&TreeNode>;
}
this compiles, so the problem is only in the implementation, I'm going out right now, good luck
^ @SCareAngel