From ae181425e0bf6e6e1010289558ee38539294a55b Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 25 Feb 2024 17:29:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=AE=BF=E9=97=AE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/src/py/class.rs | 54 ++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/ica-rs/src/py/class.rs b/ica-rs/src/py/class.rs index ffdb614..6cc2c87 100644 --- a/ica-rs/src/py/class.rs +++ b/ica-rs/src/py/class.rs @@ -1,8 +1,8 @@ use pyo3::prelude::*; use rust_socketio::asynchronous::Client; use tokio::runtime::Runtime; -use tracing::{debug, info, warn}; use toml::Value as TomlValue; +use tracing::{debug, info, warn}; use crate::client::{delete_message, send_message, IcalinguaStatus}; use crate::data_struct::messages::{ @@ -220,7 +220,6 @@ impl ConfigRequestPy { pub fn py_new(path: String) -> Self { Self { path } } } - #[derive(Clone)] #[pyclass] #[pyo3(name = "ConfigData")] @@ -232,44 +231,27 @@ pub struct ConfigDataPy { impl ConfigDataPy { pub fn __getitem__(self_: PyRef<'_, Self>, key: String) -> Option> { match self_.data.get(&key) { - Some(value) => { - match value { - TomlValue::String(s) => { - let py_value = s.into_py(self_.py()); - Some(py_value) - - }, - TomlValue::Integer(i) => { - let py_value = i.into_py(self_.py()); - Some(py_value) - }, - TomlValue::Float(f) => { - let py_value = f.into_py(self_.py()); - Some(py_value) - }, - TomlValue::Boolean(b) => { - let py_value = b.into_py(self_.py()); - Some(py_value) - }, - TomlValue::Array(a) => { - let new_self = Self::new(TomlValue::Array(a.clone())); - let py_value = new_self.into_py(self_.py()); - Some(py_value) - }, - TomlValue::Table(t) => { - let new_self = Self::new(TomlValue::Table(t.clone())); - let py_value = new_self.into_py(self_.py()); - Some(py_value) - }, - _ => None, + Some(value) => match value { + TomlValue::String(s) => Some(s.into_py(self_.py())), + TomlValue::Integer(i) => Some(i.into_py(self_.py())), + TomlValue::Float(f) => Some(f.into_py(self_.py())), + TomlValue::Boolean(b) => Some(b.into_py(self_.py())), + TomlValue::Array(a) => { + let new_self = Self::new(TomlValue::Array(a.clone())); + let py_value = new_self.into_py(self_.py()); + Some(py_value) } - } + TomlValue::Table(t) => { + let new_self = Self::new(TomlValue::Table(t.clone())); + let py_value = new_self.into_py(self_.py()); + Some(py_value) + } + _ => None, + }, None => None, } } - pub fn have_key(&self, key: String) -> bool { - self.data.get(&key).is_some() - } + pub fn have_key(&self, key: String) -> bool { self.data.get(&key).is_some() } } impl ConfigDataPy {