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