Skip to content

Migrate to Rust edition 2024#2

Open
gemenerik wants to merge 1 commit intomainfrom
rik/2024
Open

Migrate to Rust edition 2024#2
gemenerik wants to merge 1 commit intomainfrom
rik/2024

Conversation

@gemenerik
Copy link
Member

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the Rust crate to the Rust 2024 edition and makes small style refactors in a couple of async/PyO3-facing code paths.

Changes:

  • Update rust/Cargo.toml to use edition = "2024".
  • Refactor a small async return path in Platform::get_app_channel to use match.
  • Refactor Python TOC cache extraction logic in Crazyflie::connect_from_uri into nested match expressions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
rust/Cargo.toml Switch crate edition to Rust 2024.
rust/src/subsystems/platform.rs Minor refactor of get_app_channel optional return handling.
rust/src/crazyflie.rs Refactor TOC cache extraction branching logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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.
Comment on lines +96 to +109
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),
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
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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants