Created
March 24, 2021 06:54
-
-
Save cathay4t/23e38d04f47371643bda3193ac6d6c08 to your computer and use it in GitHub Desktop.
interview_rust.rs
This file contains hidden or 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 VlanInfo { | |
base_iface: String, | |
vlan_id: u16, | |
} | |
struct Iface { | |
name: String, | |
vlan_info: Option<VlanInfo>, | |
} | |
fn change_base_iface(iface: &mut Iface) { | |
if let Some(mut vlan_info) = &iface.vlan_info { | |
vlan_info.base_iface = "eth2".into(); | |
} | |
} | |
fn main() { | |
let mut iface = Iface { | |
name: "foo1".into(), | |
vlan_info: Some(VlanInfo { | |
base_iface: "eth1".into(), | |
vlan_id: 1u16, | |
}), | |
}; | |
change_base_iface(&mut iface); | |
if let Some(vlan_info) = iface.vlan_info { | |
println!("{}", vlan_info.base_iface); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.