-
-
Save aldrichtr/fe4e251d3bd741408cfc4116baa41d64 to your computer and use it in GitHub Desktop.
Function overloading paradigm in rust
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
struct SomeStruct; | |
impl SomeStruct { | |
fn new(ctor: MixedInts) { | |
match ctor { | |
_ => println!("Match arms can construct the type in different ways"), | |
} | |
} | |
} | |
enum MixedInts { | |
SmallInt(i32), | |
TwoSmallInts(i32, i32), | |
} | |
fn main() { | |
use MixedInts::*; | |
let s = SomeStruct::new(SmallInt(32)); | |
let s2 = SomeStruct::new(TwoSmallInts(32, 64)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment