Skip to content

Instantly share code, notes, and snippets.

@pzol
Created January 15, 2014 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pzol/8442591 to your computer and use it in GitHub Desktop.
Save pzol/8442591 to your computer and use it in GitHub Desktop.
destructuring structs
#[feature(struct_variant)];
struct Bar { num: int}
#[test]
fn test_bar() {
let bar = Bar { num: 1 };
let Bar { num } = bar;
assert!(num == 1);
}
enum Fagazi {
Fob { a: int },
Foo { b: int, c: int }
}
#[test]
fn test_foo() {
let foo = Foo { b: 1, c: 2 };
let Foo { b, c } = foo;
}
@pzol
Copy link
Author

pzol commented Jan 15, 2014

/Users/pzol/Dropbox/src/rust/one/src/destructuring_test.rs:21:7: 21:19 error: refutable pattern in local binding
/Users/pzol/Dropbox/src/rust/one/src/destructuring_test.rs:21 let Foo { b, c } = foo;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment