Created
March 25, 2018 08:25
-
-
Save yoshuawuyts/88fdcff4d0099e8060f10cc4ef60e314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This version gives a "cannot move out of borrowed content error" | |
let ref fd = &self.fd.unwrap(); | |
// But I guess that's fair game. Docs say it "moves" content, which | |
// is not what we want. How about expect? | |
let ref fd = &self.fd.expect("Invalid state: no fd found in Sync::Write"); | |
// Nope, also doesn't work. This is the only version that works fine. | |
let fd = match &self.fd { | |
&Some(ref fd) => fd, | |
&None => panic!("Invalid state: no fd found in Sync::Write"), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution was to do:
Which gives us a reference that can be
move
d by.expect()
. Autoref prevents the need to then call itlet ref fd =