mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
config_control.rs: Eliminate vector reallocation from get_nic_list
Refactor the get_nic_list function to use iterators with a collect at the end, ensuring that the result vector is allocated at exactly the needed size.
This commit is contained in:
parent
7cb8f930d1
commit
d0dd559f1d
@ -16,15 +16,22 @@ pub async fn config_page<'a>(_auth: AuthGuard) -> NoCache<Option<NamedFile>> {
|
||||
|
||||
#[get("/api/list_nics")]
|
||||
pub async fn get_nic_list<'a>(_auth: AuthGuard) -> NoCache<Json<Vec<(String, String, String)>>> {
|
||||
let mut result = Vec::new();
|
||||
for eth in get_interfaces().iter() {
|
||||
let mac = if let Some(mac) = ð.mac_addr {
|
||||
mac.to_string()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
result.push((eth.name.clone(), format!("{:?}", eth.if_type), mac));
|
||||
}
|
||||
let result = get_interfaces()
|
||||
.iter()
|
||||
.map(|eth| {
|
||||
let mac = if let Some(mac) = ð.mac_addr {
|
||||
mac.to_string()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
(
|
||||
eth.name.clone(),
|
||||
format!("{:?}", eth.if_type),
|
||||
mac
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
NoCache::new(Json(result))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user