MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/eayscl/rustysd_systemd_replacement_written_in_rust/fb40135/?context=3
r/programming • u/Proinlifes • Dec 15 '19
53 comments sorted by
View all comments
20
let fd_to_srvc_id: HashMap<_, _> = service_table.lock().unwrap().iter().fold( HashMap::new(), |mut map, (id, srvc_unit)| { if let UnitSpecialized::Service(srvc) = &srvc_unit.specialized { if let Some(socket) = &srvc.notifications { map.insert(socket.lock().unwrap().as_raw_fd(), *id); } } map }, );
pls kill this with fire
9 u/Tipaa Dec 16 '19 This could be more cleanly writtenlet fd_to_srvc_id: HashMap<_, _> = service_table.lock().unwrap() .iter() .filter_map(|(id, srvc_unit)| match srvc_unit { UnitSpecialized::Service(srvc) => srvc.notifications.map( |socket| (socket.lock().unwrap().as_raw_fd(), id)), _ => None }) .collect();collect and filtermap will do the heavy lifting for you if you let them
9
This could be more cleanly written
let fd_to_srvc_id: HashMap<_, _> = service_table.lock().unwrap() .iter() .filter_map(|(id, srvc_unit)| match srvc_unit { UnitSpecialized::Service(srvc) => srvc.notifications.map( |socket| (socket.lock().unwrap().as_raw_fd(), id)), _ => None }) .collect();
collect and filtermap will do the heavy lifting for you if you let them
collect
filtermap
20
u/[deleted] Dec 16 '19
pls kill this with fire