These are chat archives for rust-lang/rust

16th
Aug 2016
Johann Tuffe
@tafia
Aug 16 2016 00:15
Either that or return a Box<.
Box<TreeNode>
Peter Atashian
@retep998
Aug 16 2016 01:37
I'm not sure impl trait will work too well when self is a trait object already
Returning a Box is probably the only option
Although, if you just return &Trait instead of &Self it should work fine
or maybe not, this is confusing
Peter Atashian
@retep998
Aug 16 2016 01:43
Okay, as far as I can tell its just an issue with doing it in the default impl
if you just manually implement it for every type then it somehow works fine
trait X {
    fn into_trait(&self) -> &X;
}
impl X for i32 { fn into_trait(&self) -> &X { self } }
messense
@messense
Aug 16 2016 02:15
Hi everyone, I wrote a simple tool to highlight rustc --explain output in command line. https://github.com/messense/rusted
Fletcher Haynes
@fhaynes
Aug 16 2016 03:47

Hello! I have a struct with a field like:

token: Option<String>

When I try give ownership of that struct to a function, it complains about that field not implementing Copy. Attempting to derive it fails...is there a way to make that work?

Johann Tuffe
@tafia
Aug 16 2016 03:56
Are you sure you're moving ownership of the entire struct? It shouldn't need copy then.
If what you want is to give ownership of that particular token then look for Option::take
Fletcher Haynes
@fhaynes
Aug 16 2016 03:58
I think so...
let my_struct = func_that_returns_struct();
while some_condition == true {
another_struct.func_that_takes_my_struct(my_struct);
}
forgot about the while loop
I'm guessing it is because I bind it outside the loop and try to give up ownership inside the loop? But I could theoretically use it once the loop has terminated?
Hrm, the while loop would terminate after the function inside it is called, but Rust wouldn't know that either...
Johann Tuffe
@tafia
Aug 16 2016 04:02
Yes indeed
Fletcher Haynes
@fhaynes
Aug 16 2016 04:03
I will not kill the borrow checker, I will not kill the borrow checker...
Johann Tuffe
@tafia
Aug 16 2016 04:04
:)
Fletcher Haynes
@fhaynes
Aug 16 2016 04:10
HA! Take that Mr. Borrow Checker! take() worked fine, thank you @tafia
Zakarum
@omni-viral
Aug 16 2016 08:46
@Bastacyclop thanks )