tony / oxwm

layout/mod.rs: apply clippy lints Browse files
- renamed `LayoutType::new` => `LayoutType::to_boxed_layout` as `new`
did not return `Self`

- removed method `LayoutType::from_str` and implemented `FromStr` Trait
instead.
emzywastaken committed 2025-12-15 parent dcb6d02 commit 3816a444c2a7b2096fb3a05e7cab1751cfff39f6
Showing 1 changed file with 9 additions and 3 deletions. UnifiedSplit
+9 −3 src/layout/mod.rs
@@ -4,6 +4,8 @@ pub mod normie;
4 pub mod tabbed; 4 pub mod tabbed;
5 pub mod tiling; 5 pub mod tiling;
6 6
7 +use std::str::FromStr;
8 +
7 use x11rb::protocol::xproto::Window; 9 use x11rb::protocol::xproto::Window;
8 10
9 pub type LayoutBox = Box<dyn Layout>; 11 pub type LayoutBox = Box<dyn Layout>;
@@ -24,7 +26,7 @@ pub enum LayoutType {
24 } 26 }
25 27
26 impl LayoutType { 28 impl LayoutType {
27 - pub fn new(&self) -> LayoutBox { 29 + pub fn to_boxed_layout(&self) -> LayoutBox {
28 match self { 30 match self {
29 Self::Tiling => Box::new(tiling::TilingLayout), 31 Self::Tiling => Box::new(tiling::TilingLayout),
30 Self::Normie => Box::new(normie::NormieLayout), 32 Self::Normie => Box::new(normie::NormieLayout),
@@ -53,8 +55,12 @@ impl LayoutType {
53 Self::Tabbed => "tabbed", 55 Self::Tabbed => "tabbed",
54 } 56 }
55 } 57 }
58 +}
59 +
60 +impl FromStr for LayoutType {
61 + type Err = String;
56 62
57 - pub fn from_str(s: &str) -> Result<Self, String> { 63 + fn from_str(s: &str) -> Result<Self, String> {
58 match s.to_lowercase().as_str() { 64 match s.to_lowercase().as_str() {
59 "tiling" => Ok(Self::Tiling), 65 "tiling" => Ok(Self::Tiling),
60 "normie" | "floating" => Ok(Self::Normie), 66 "normie" | "floating" => Ok(Self::Normie),
@@ -68,7 +74,7 @@ impl LayoutType {
68 74
69 pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> { 75 pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> {
70 let layout_type = LayoutType::from_str(s)?; 76 let layout_type = LayoutType::from_str(s)?;
71 - Ok(layout_type.new()) 77 + Ok(layout_type.to_boxed_layout())
72 } 78 }
73 79
74 pub fn next_layout(current_name: &str) -> &'static str { 80 pub fn next_layout(current_name: &str) -> &'static str {