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.
+9 −3 src/layout/mod.rs
| @@ -4,6 +4,8 @@ pub mod normie; | ||
| 4 | 4 | pub mod tabbed; |
| 5 | 5 | pub mod tiling; |
| 6 | 6 | |
| 7 | +use std::str::FromStr; | |
| 8 | + | |
| 7 | 9 | use x11rb::protocol::xproto::Window; |
| 8 | 10 | |
| 9 | 11 | pub type LayoutBox = Box<dyn Layout>; |
| @@ -24,7 +26,7 @@ pub enum LayoutType { | ||
| 24 | 26 | } |
| 25 | 27 | |
| 26 | 28 | impl LayoutType { |
| 27 | - pub fn new(&self) -> LayoutBox { | |
| 29 | + pub fn to_boxed_layout(&self) -> LayoutBox { | |
| 28 | 30 | match self { |
| 29 | 31 | Self::Tiling => Box::new(tiling::TilingLayout), |
| 30 | 32 | Self::Normie => Box::new(normie::NormieLayout), |
| @@ -53,8 +55,12 @@ impl LayoutType { | ||
| 53 | 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 | 64 | match s.to_lowercase().as_str() { |
| 59 | 65 | "tiling" => Ok(Self::Tiling), |
| 60 | 66 | "normie" | "floating" => Ok(Self::Normie), |
| @@ -68,7 +74,7 @@ impl LayoutType { | ||
| 68 | 74 | |
| 69 | 75 | pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> { |
| 70 | 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 | 80 | pub fn next_layout(current_name: &str) -> &'static str { |