Skip to content

Commit 9cc122e

Browse files
committed
fix: resolve clippy type complexity and serde derive issues
- Add type aliases to fix clippy type complexity warnings in examples - Fix serde derive imports with conditional compilation guards - Resolve CI build failures from missing derive macros - Improve code readability with simplified type signatures Technical changes: - examples/bbl_crate_test.rs: Add PidValues, PidWithFf type aliases - src/export.rs: Add conditional serde imports for feature gates - Ensure all clippy and formatting checks pass
1 parent 7be2bac commit 9cc122e

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

.github/copilot-instructions.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434

3535
## Committing Rules
3636
- **Commit Conditions:** Only commit if:
37-
- `cargo clippy -- -D warnings` passes.
37+
- `cargo clippy --all-targets --all-features -- -D warnings` passes.
3838
- `cargo fmt --all -- --check` passes.
3939
- `cargo test --verbose` passes.
4040
- `cargo test --features=cli --verbose` passes.
41+
- `cargo build --release` passes with no errors or warnings.
4142
- **Files to Commit:**
4243
- Only `src/**/*.rs`, `Cargo.*`, `README.md`, `OVERVIEW.md` and `.gitignore` — never `git add .` or `git add -A`.
4344
- Follow `.gitignore`.
@@ -46,3 +47,11 @@
4647
- Check `git diff --cached` before committing.
4748
- Use concise commit messages and descriptions.
4849
- Use `feat:`, `fix:`, `docs:` where applicable.
50+
51+
## Mandatory Checks
52+
- **BEFORE ANY CODE CHANGES:** Always run `cargo clippy --all-targets --all-features -- -D warnings` to catch ALL issues.
53+
- **BEFORE ANY CODE CHANGES:** Always run `cargo fmt --all -- --check` to ensure formatting compliance.
54+
- **NO OPTIONAL FEATURES ERRORS:** All feature combinations must compile without errors.
55+
- **NO FORMATTING VIOLATIONS:** Code must pass `cargo fmt --all -- --check` without any formatting issues.
56+
- **STRICT COMPLIANCE:** Never skip clippy checks or formatting checks. Never allow warnings to pass.
57+
- **IMMEDIATE FORMATTING:** Apply `cargo fmt --all` immediately if formatting check fails.

examples/bbl_crate_test.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ use clap::Parser;
44
use glob::glob;
55
use std::path::{Path, PathBuf};
66

7+
// Type aliases to simplify complex PID tuples
8+
type PidValues = (i32, i32, i32);
9+
type PidWithFf = (i32, i32, i32, i32);
10+
type ThreePidValues = (PidValues, PidValues, PidValues);
11+
type ThreePidWithFf = (PidWithFf, PidWithFf, PidWithFf);
12+
713
#[derive(Parser)]
814
#[command(name = "bbl_crate_test")]
915
#[command(about = "Test program demonstrating BBL parser crate usage")]
@@ -179,13 +185,7 @@ fn display_pid_settings(all_headers: &[String]) {
179185
}
180186

181187
/// Parse PID values with feedforward from raw header lines (for iNav 4-value format)
182-
fn parse_pid_with_ff_from_headers(
183-
all_headers: &[String],
184-
) -> Option<(
185-
(i32, i32, i32, i32),
186-
(i32, i32, i32, i32),
187-
(i32, i32, i32, i32),
188-
)> {
188+
fn parse_pid_with_ff_from_headers(all_headers: &[String]) -> Option<ThreePidWithFf> {
189189
let mut roll_pid = None;
190190
let mut pitch_pid = None;
191191
let mut yaw_pid = None;
@@ -214,9 +214,7 @@ fn parse_pid_with_ff_from_headers(
214214
}
215215

216216
/// Parse PID values from raw header lines (for Betaflight rollPID/pitchPID/yawPID format)
217-
fn parse_pid_from_headers(
218-
all_headers: &[String],
219-
) -> Option<((i32, i32, i32), (i32, i32, i32), (i32, i32, i32))> {
217+
fn parse_pid_from_headers(all_headers: &[String]) -> Option<ThreePidValues> {
220218
let mut roll_pid = None;
221219
let mut pitch_pid = None;
222220
let mut yaw_pid = None;
@@ -245,7 +243,7 @@ fn parse_pid_from_headers(
245243
}
246244

247245
/// Parse feedforward values from raw header lines (Betaflight ff_weight format)
248-
fn parse_feedforward_from_headers(all_headers: &[String]) -> Option<(i32, i32, i32)> {
246+
fn parse_feedforward_from_headers(all_headers: &[String]) -> Option<PidValues> {
249247
for header in all_headers {
250248
if header.starts_with("H ff_weight:") {
251249
if let Some(value_str) = header.strip_prefix("H ff_weight:") {
@@ -259,7 +257,7 @@ fn parse_feedforward_from_headers(all_headers: &[String]) -> Option<(i32, i32, i
259257
}
260258

261259
/// Parse PID string in format "P,I,D,FF" and return (P, I, D, FF) tuple
262-
fn parse_pid_with_ff_string(pid_value: &str) -> Option<(i32, i32, i32, i32)> {
260+
fn parse_pid_with_ff_string(pid_value: &str) -> Option<PidWithFf> {
263261
// Remove quotes if present
264262
let cleaned = pid_value.trim_matches('"');
265263

@@ -278,7 +276,7 @@ fn parse_pid_with_ff_string(pid_value: &str) -> Option<(i32, i32, i32, i32)> {
278276
}
279277

280278
/// Parse PID string in format "P,I,D" or "P,I,D,FF" and return (P, I, D) tuple
281-
fn parse_pid_string(pid_value: &str) -> Option<(i32, i32, i32)> {
279+
fn parse_pid_string(pid_value: &str) -> Option<PidValues> {
282280
// Remove quotes if present
283281
let cleaned = pid_value.trim_matches('"');
284282

src/export.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use crate::types::*;
77
use crate::Result;
88
use std::path::Path;
99

10+
#[cfg(feature = "serde")]
11+
use serde::{Deserialize, Serialize};
12+
1013
/// Export options for various output formats
1114
#[derive(Debug, Clone, Default)]
1215
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

0 commit comments

Comments
 (0)