wlancfg_lib/client/connection_selection/
network_selection.rs1use crate::client::types;
6use std::collections::HashSet;
7
8pub fn select_networks(
11 available_networks: HashSet<types::NetworkIdentifier>,
12 network: &Option<types::NetworkIdentifier>,
13) -> HashSet<types::NetworkIdentifier> {
14 match network {
15 Some(network) => HashSet::from([network.clone()]),
16 None => {
17 available_networks
21 }
22 }
23}
24
25#[cfg(test)]
26mod test {
27
28 use super::*;
29 #[fuchsia::test]
30 fn select_networks_selects_specified_network() {
31 let ssid = "foo";
32 let all_networks = vec![
33 types::NetworkIdentifier {
34 ssid: ssid.try_into().unwrap(),
35 security_type: types::SecurityType::Wpa3,
36 },
37 types::NetworkIdentifier {
38 ssid: ssid.try_into().unwrap(),
39 security_type: types::SecurityType::Wpa2,
40 },
41 ];
42 let all_network_set = HashSet::from_iter(all_networks.clone());
43
44 let desired_network = all_networks[0].clone();
46 let selected_network =
47 select_networks(all_network_set.clone(), &Some(desired_network.clone()));
48 assert_eq!(selected_network, HashSet::from([desired_network]));
49
50 assert_eq!(select_networks(all_network_set.clone(), &None), all_network_set);
52 }
53}