diff --git a/rust/Cargo.toml b/rust/Cargo.toml index c2b6220..e815d0f 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cflib-rust" version = "0.1.0" -edition = "2021" +edition = "2024" [lib] name = "cflib_rust" diff --git a/rust/src/crazyflie.rs b/rust/src/crazyflie.rs index f0ad7bc..5ab810b 100644 --- a/rust/src/crazyflie.rs +++ b/rust/src/crazyflie.rs @@ -93,22 +93,20 @@ impl Crazyflie { toc_cache: Option<&Bound<'_, PyAny>>, ) -> PyResult> { // Extract cache from Python object - let cache = if let Some(cache_obj) = toc_cache { - // Try to extract each cache type - if let Ok(no_cache) = cache_obj.extract::() { - AnyCacheWrapper::NoCache(no_cache) - } else if let Ok(mem_cache) = cache_obj.extract::() { - AnyCacheWrapper::InMemory(mem_cache) - } else if let Ok(file_cache) = cache_obj.extract::() { - AnyCacheWrapper::File(file_cache) - } else { - return Err(PyRuntimeError::new_err( - "toc_cache must be NoTocCache, InMemoryTocCache, or FileTocCache" - )); - } - } else { - // Default to NoTocCache - AnyCacheWrapper::NoCache(NoTocCache) + let cache = match toc_cache { + Some(cache_obj) => match cache_obj.extract::() { + Ok(no_cache) => AnyCacheWrapper::NoCache(no_cache), + _ => match cache_obj.extract::() { + Ok(mem_cache) => AnyCacheWrapper::InMemory(mem_cache), + _ => match cache_obj.extract::() { + Ok(file_cache) => AnyCacheWrapper::File(file_cache), + _ => return Err(PyRuntimeError::new_err( + "toc_cache must be NoTocCache, InMemoryTocCache, or FileTocCache" + )), + }, + }, + }, + None => AnyCacheWrapper::NoCache(NoTocCache), }; let link_context_inner = link_context.inner.clone(); diff --git a/rust/src/subsystems/platform.rs b/rust/src/subsystems/platform.rs index ff14c85..b8558ff 100644 --- a/rust/src/subsystems/platform.rs +++ b/rust/src/subsystems/platform.rs @@ -145,10 +145,9 @@ impl Platform { fn get_app_channel<'py>(&self, py: Python<'py>) -> PyResult> { let cf = self.cf.clone(); pyo3_async_runtimes::tokio::future_into_py(py, async move { - if let Some((tx, rx)) = cf.platform.get_app_channel().await { - Ok(Some(AppChannel::new(tx, rx))) - } else { - Ok(None) + match cf.platform.get_app_channel().await { + Some((tx, rx)) => Ok(Some(AppChannel::new(tx, rx))), + None => Ok(None), } }) }