From 47737e26a2ce8717eac68aa08dccdcc0590742a1 Mon Sep 17 00:00:00 2001 From: Louis Thiery Date: Wed, 22 May 2024 08:24:09 -0700 Subject: [PATCH] sta: impl Display instead of ToString directly --- src/sta/mod.rs | 2 +- src/sta/types.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sta/mod.rs b/src/sta/mod.rs index dd16ca4..f52f7e3 100644 --- a/src/sta/mod.rs +++ b/src/sta/mod.rs @@ -229,7 +229,7 @@ impl WifiStation { match param { SetNetwork::Ssid(ssid) => format!("ssid \"{ssid}\""), SetNetwork::Psk(psk) => format!("psk \"{psk}\""), - SetNetwork::KeyMgmt(mgmt) => format!("key_mgmt {}", mgmt.to_string()), + SetNetwork::KeyMgmt(mgmt) => format!("key_mgmt {}", mgmt), } ); debug!("wpa_ctrl \"{cmd}\""); diff --git a/src/sta/types.rs b/src/sta/types.rs index f8ca472..c55cdfe 100644 --- a/src/sta/types.rs +++ b/src/sta/types.rs @@ -1,6 +1,7 @@ use super::{error, warn, Result}; use serde::Serialize; use std::collections::HashMap; +use std::fmt::Display; use std::str::FromStr; use tokio::net::UnixDatagram; @@ -125,13 +126,14 @@ pub enum KeyMgmt { IEEE8021X, } -impl ToString for KeyMgmt { - fn to_string(&self) -> String { - match self { +impl Display for KeyMgmt { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let str = match self { KeyMgmt::None => "NONE".to_string(), KeyMgmt::WpaPsk => "WPA-PSK".to_string(), KeyMgmt::WpaEap => "WPA-EAP".to_string(), KeyMgmt::IEEE8021X => "IEEE8021X".to_string(), - } + }; + write!(f, "{}", str) } }