I've searched for this, but only found ways to display the actual Enum "type" itself rather than the "stored value."
See the following code for what I'm trying to do:
enum IpAddr {
V4(String),
V6(String),
}
fn main()
{
let home = IpAddr::V4(String::from("127.0.0.1"));
let loopback = IpAddr::V6(String::from("::1"));
print_ip(home);
}
fn print_ip(ip: Option<IpAddr>)
{
match ip
{
Some(val) => println!("{}", val),
None => println!("No value to print!")
}
}
This does not compile whether I specify the ip parameter as a IpAddr directly, or an Option as shown here. I'm looking for the simplest way to write out the value stored in the enum, which in this case are Strings. Is there a way to access the value directly or must I use a match? Thank you.