Skip to content

Instantly share code, notes, and snippets.

@zmack
Created December 16, 2014 19:55
Show Gist options
  • Save zmack/07826f941366cdbad10c to your computer and use it in GitHub Desktop.
Save zmack/07826f941366cdbad10c to your computer and use it in GitHub Desktop.
#[deriving(Show,Clone)]
enum DiskStruct {
File(String),
Dir(String)
}
impl DiskStruct {
fn new(path: &str) -> DiskStruct {
match path.slice_from(path.len()-1) {
"/" => DiskStruct::Dir(path.to_string()),
_ => DiskStruct::File(path.to_string())
}
}
fn path(self) -> String {
match self {
DiskStruct::File(s) => s.clone(),
DiskStruct::Dir(s) => s.clone()
}
}
fn foo(&self) {
println!("Self is {}", (*self).clone().path());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment