use filter().map()
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -129,23 +129,22 @@ fn get_layouts() -> Vec<String> {
|
||||
let mut layout_names: Vec<String> = Vec::new();
|
||||
|
||||
// Get the names of monitors that are available (that match a current output)
|
||||
let mut available_monitor_names: Vec<String> = Vec::new();
|
||||
// TODO do this with iterators
|
||||
rules.monitors.iter().for_each(|(monitor_name, monitor)| {
|
||||
if available_outputs.iter().any(|output| {
|
||||
let available_monitor_names:Vec<&String> = rules.monitors.iter()
|
||||
.filter(|(_monitor_name,monitor)|
|
||||
available_outputs.iter().any(|output|
|
||||
monitor.make == output.make
|
||||
&& monitor.model == output.model
|
||||
&& output.serial == monitor.serial
|
||||
}) {
|
||||
available_monitor_names.push(String::from(monitor_name));
|
||||
}
|
||||
});
|
||||
)
|
||||
)
|
||||
.map(|(monitor_name,_monitor)| monitor_name)
|
||||
.collect();
|
||||
|
||||
// Add each layout defined in the config file for which all outputs are available
|
||||
rules.layouts.iter().for_each(|(layout_name, layout)| {
|
||||
if layout
|
||||
.iter()
|
||||
.all(|(output_name, _output)| available_monitor_names.contains(output_name))
|
||||
.all(|(output_name, _output)| available_monitor_names.contains(&output_name))
|
||||
{
|
||||
layout_names.push(String::from(layout_name))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user