Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cflib-rust"
version = "0.1.0"
edition = "2021"
edition = "2024"
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching the crate to edition 2024 effectively raises the minimum supported Rust toolchain (older compilers will fail to parse/build). To make this explicit and avoid confusing build failures in downstream environments, add an explicit MSRV (e.g., rust-version) and/or a repo-level toolchain pin (rust-toolchain.toml) that matches the intended minimum.

Suggested change
edition = "2024"
edition = "2024"
rust-version = "1.85"

Copilot uses AI. Check for mistakes.

[lib]
name = "cflib_rust"
Expand Down
30 changes: 14 additions & 16 deletions rust/src/crazyflie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,20 @@ impl Crazyflie {
toc_cache: Option<&Bound<'_, PyAny>>,
) -> PyResult<Bound<'py, PyAny>> {
// 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::<NoTocCache>() {
AnyCacheWrapper::NoCache(no_cache)
} else if let Ok(mem_cache) = cache_obj.extract::<InMemoryTocCache>() {
AnyCacheWrapper::InMemory(mem_cache)
} else if let Ok(file_cache) = cache_obj.extract::<FileTocCache>() {
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::<NoTocCache>() {
Ok(no_cache) => AnyCacheWrapper::NoCache(no_cache),
_ => match cache_obj.extract::<InMemoryTocCache>() {
Ok(mem_cache) => AnyCacheWrapper::InMemory(mem_cache),
_ => match cache_obj.extract::<FileTocCache>() {
Ok(file_cache) => AnyCacheWrapper::File(file_cache),
_ => return Err(PyRuntimeError::new_err(
"toc_cache must be NoTocCache, InMemoryTocCache, or FileTocCache"
)),
},
},
},
None => AnyCacheWrapper::NoCache(NoTocCache),
Comment on lines +96 to +109
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new nested match chain for toc_cache extraction increases indentation and is harder to read/extend than the previous sequential checks. Consider refactoring back to a flat sequence (e.g., if let Ok(...) / else if ...) or using combinators/helper function to try each extract in order, to keep control flow simpler.

Suggested change
let cache = match toc_cache {
Some(cache_obj) => match cache_obj.extract::<NoTocCache>() {
Ok(no_cache) => AnyCacheWrapper::NoCache(no_cache),
_ => match cache_obj.extract::<InMemoryTocCache>() {
Ok(mem_cache) => AnyCacheWrapper::InMemory(mem_cache),
_ => match cache_obj.extract::<FileTocCache>() {
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 cache = if let Some(cache_obj) = toc_cache {
if let Ok(no_cache) = cache_obj.extract::<NoTocCache>() {
AnyCacheWrapper::NoCache(no_cache)
} else if let Ok(mem_cache) = cache_obj.extract::<InMemoryTocCache>() {
AnyCacheWrapper::InMemory(mem_cache)
} else if let Ok(file_cache) = cache_obj.extract::<FileTocCache>() {
AnyCacheWrapper::File(file_cache)
} else {
return Err(PyRuntimeError::new_err(
"toc_cache must be NoTocCache, InMemoryTocCache, or FileTocCache"
));
}
} else {
AnyCacheWrapper::NoCache(NoTocCache)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fix --edition did this for me,

};

let link_context_inner = link_context.inner.clone();
Expand Down
7 changes: 3 additions & 4 deletions rust/src/subsystems/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ impl Platform {
fn get_app_channel<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
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),
}
})
}
Expand Down
Loading