Skip to content

Instantly share code, notes, and snippets.

Created February 5, 2017 18:39
Show Gist options
  • Save anonymous/17b5375c5584e8c7ea7e476d012a750a to your computer and use it in GitHub Desktop.
Save anonymous/17b5375c5584e8c7ea7e476d012a750a to your computer and use it in GitHub Desktop.
Shared via Rust Playground
use std::mem;
#[derive(Debug)]
pub struct SaveResult {
sentinel: i64,
dir: SaveDir,
}
#[derive(Debug)]
pub enum SaveDir {
Temp(String),
Perm(String),
}
impl SaveDir {
pub fn keep(&mut self) {
use self::SaveDir::*;
*self = match mem::replace(self, Perm(String::new())) {
Temp(tempdir) => Perm(tempdir),
old_self => old_self,
};
}
}
fn main() {
let x = test_case();
}
fn test_case() -> SaveDir {
// we create some enum ...
let dir = SaveDir::Temp(String::from("foo"));
// we need this foo_result "wrapper" because the ICE seems related to this
// enum being partially moved out of a struct...
let foo_result = SaveResult { sentinel: 42, dir: dir };
// we try to convert it to its "permanent" variant
// this is not actually legal, foo_result needs to be a mutable binding
// if you do `let mut foo_result = ...;` above this won't ICE (!!!)
foo_result.dir.keep(); foo_result.dir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment