我有这样一个有效的代码:
/* Ignore IPv6. */
let via = if let IpAddr::V4(via) = addr.ip() {
via
} else {
warn!("(unsupported) ipv6 packet from ${addr}");
continue // abandon this packet and try the next packet
};
// ...process this packet with "via: Ipv4Addr" in scope...
有没有一种惯用的方法可以从枚举中取出想要的变体,而不会三次提到via
?
或者,这是我应该忽略Rust中不想要的变体的方式吗?