enum T {
A(Vec<u8>),
B(Vec<u8>)
}
let a = T::A(Vec::new());
let b = T::B(Vec::new());
if let (T::A(a),T::B(b)) = (a,b) {
drop(a);
drop(b);
}else {
drop(a);
drop(b);
}
Codes above cannot be passed, with errmessage of use of moved value a,b.
enum T {
A(Vec<u8>),
B(Vec<u8>)
}
let a = T::A(Vec::new());
let b = T::B(Vec::new());
if let T::A(n) = a {
drop(n);
}else {
drop(a);
}
Because the expression you use to create your tuple (a, b)movesa and b into the tuple. The tuple takes ownership of the values. You can't use a or b after creating your tuple, because they got moved. If you want to prevent moving a and b you can instead use references when creating your tuple, changing its data type from (T, T) to (&T, &T):
if let (T::A(a),T::B(b)) = (&a, &b) {
drop(a);
drop(b);
}else {
drop(a);
drop(b);
}
enum T {
A(Vec<u8>),
B(Vec<u8>)
}
let a = T::A(Vec::new());
let b = T::B(Vec::new());
if let T::A(a) = a {
if let T::B(b) = b {
drop(a);
drop(b);
}else {
// do something
}
}else {
drop(a);
drop(b)
}