Skip to content

Instantly share code, notes, and snippets.

@aldrichtr
Forked from anonymous/playground.rs
Last active July 25, 2024 17:49
Show Gist options
  • Save aldrichtr/fe4e251d3bd741408cfc4116baa41d64 to your computer and use it in GitHub Desktop.
Save aldrichtr/fe4e251d3bd741408cfc4116baa41d64 to your computer and use it in GitHub Desktop.
Function overloading paradigm in rust
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