Created
April 23, 2020 15:36
-
-
Save MightyPork/3257563ce062a6b28ae3df5784753838 to your computer and use it in GitHub Desktop.
rust tuple flattening
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod tuple_flatten { | |
pub trait TupleFlatten3<A, B, C> { | |
fn flatten(self) -> (A, B, C); | |
} | |
impl<A, B, C> TupleFlatten3<A, B, C> for (A, (B, C)) { | |
fn flatten(self) -> (A, B, C) { | |
(self.0, (self.1).0, (self.1).1) | |
} | |
} | |
impl<A, B, C> TupleFlatten3<A, B, C> for ((A, B), C) { | |
fn flatten(self) -> (A, B, C) { | |
((self.0).0, (self.0).1, self.1) | |
} | |
} | |
pub trait TupleFlatten4<A, B, C, D> { | |
fn flatten(self) -> (A, B, C, D); | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for (A, B, (C, D)) { | |
fn flatten(self) -> (A, B, C, D) { | |
(self.0, self.1, (self.2).0, (self.2).1) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for (A, (B, C), D) { | |
fn flatten(self) -> (A, B, C, D) { | |
(self.0, (self.1).0, (self.1).1, self.2) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for ((A, B), C, D) { | |
fn flatten(self) -> (A, B, C, D) { | |
((self.0).0, (self.0).1, self.1, self.2) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for (A, (B, C, D)) { | |
fn flatten(self) -> (A, B, C, D) { | |
(self.0, (self.1).0, (self.1).1, (self.1).2) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for ((A, B, C), D) { | |
fn flatten(self) -> (A, B, C, D) { | |
((self.0).0, (self.0).1, (self.0).2, self.1) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for (A, (B, (C, D))) { | |
fn flatten(self) -> (A, B, C, D) { | |
(self.0, (self.1).0, ((self.1).1).0, ((self.1).1).1) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for (A, ((B, C), D)) { | |
fn flatten(self) -> (A, B, C, D) { | |
(self.0, ((self.1).0).0, ((self.1).0).1, (self.1).1) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for ((A, (B, C)), D) { | |
fn flatten(self) -> (A, B, C, D) { | |
((self.0).0, ((self.0).1).0, ((self.0).1).1, self.1) | |
} | |
} | |
impl<A, B, C, D> TupleFlatten4<A, B, C, D> for (((A, B), C), D) { | |
fn flatten(self) -> (A, B, C, D) { | |
(((self.0).0).0, ((self.0).0).1, (self.0).1, self.1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment