Here's a swap function for two-element tuples:
fn swap<A, B>(obj: (A, B)) -> (B, A) { let (a, b) = obj; (b, a) }
Usage example:
fn main() { let obj = (10i, 20i); println!("{}", swap(obj)); }
Is there a way to define swap as a method for two-element tuples? That is, so that it can be called as:
(10i, 20i).swap()
methods tuples rust
dharmatech
source share