Created
March 27, 2021 14:45
-
-
Save rikkix/5e16033834d727ae90dbdd622f3b8490 to your computer and use it in GitHub Desktop.
first attempt on 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
enum IPAddr { | |
IPv4(u8, u8, u8, u8), | |
IPv6(String), | |
} | |
fn main() { | |
let ip1 = IPAddr::IPv4(127, 0, 0, 1); | |
let ip2 = IPAddr::IPv6(String::from("::1")); | |
print_ip(&ip1); | |
print_ip(&ip2); | |
} | |
fn print_ip(ip: &IPAddr) { | |
match ip { | |
IPAddr::IPv4(a, b, c, d) => | |
println!("IPv4: {}.{}.{}.{}", a, b, c, d), | |
IPAddr::IPv6(ip) => | |
println!("IPv6: {}", ip), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment