From c5f35ebf0624452da9f35a7045d4f025ddd5acb8 Mon Sep 17 00:00:00 2001 From: stephen Date: Tue, 31 Dec 2024 02:46:35 +0000 Subject: [PATCH] Use HashSet for available layout names to avoid monitor-layout dup --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 13 ++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2930c0e..fb8211b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,7 +192,7 @@ dependencies = [ [[package]] name = "swayout" -version = "1.1.0" +version = "1.1.1" dependencies = [ "kdl", "serde", diff --git a/Cargo.toml b/Cargo.toml index c01836b..c00499c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swayout" -version = "1.1.0" +version = "1.1.1" edition = "2021" description = "A tool to configure sway outputs" authors = ["Stephen Byrne"] diff --git a/src/lib.rs b/src/lib.rs index 065a558..fd5775c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; mod config; use crate::config::{get_config, Config, Layout, OutputConfig}; @@ -11,18 +11,17 @@ use crate::sway::{apply_outputs, get_outputs, Output}; /// for which all outputs are available, /// one for each monitor defined in the configuration file (for using just that monitor), /// and one for each available output that is not a configured monitor (for using just that output). -fn get_layouts() -> Vec { +fn get_layouts() -> HashSet { let available_outputs = get_outputs(); let config = get_config(); - - let mut layout_names: Vec = Vec::new(); + let mut layout_names: HashSet = HashSet::new(); // Add each layout defined in the config file for which all outputs are available get_available_layouts(&config, &available_outputs) .iter() .for_each(|layout| { - layout_names.push(String::from(&layout.name)); + layout_names.insert(String::from(&layout.name)); }); // add each individual output (by monitor name if the monitor is defined, else by output name) @@ -35,9 +34,9 @@ fn get_layouts() -> Vec { && monitor.serial == output.serial }); if let Some(monitor) = monitor_opt { - layout_names.push(String::from(&monitor.name)); + layout_names.insert(String::from(&monitor.name)); } else { - layout_names.push(String::from(&output.name)); + layout_names.insert(String::from(&output.name)); } });