Clear the clippy warnings, except the two that are not cosmetic
Down from 29 warnings to 2, in the spirit of 4ab95ff.
The doc warnings were all one mistake made repeatedly: a paragraph wrapped so
that a line *began* with `- ` or `+ `, which rustdoc reads as a markdown list
marker and the following lines as unindented continuations. The prose always
meant an em-dash. Fixed by moving the dash to the end of the previous line and
re-wrapping; not one word changed, which is the point - these comments record
things confirmed against real printers and are worth more than the warning.
The genuine lists just had their continuations de-indented and stayed lists.
The code ones are `match x { V(v) => .., _ => {} }` to `if let`, and nested
`if let Some(x) = .. { if cond { .. } }` to a let-chain. None had an `else`,
so each is the same control flow written once instead of twice.
Two warnings are left deliberately, because fixing them is not cosmetic:
`AmsTray` (544 bytes against 32) and `BambuReport` (984 against 120) both have
one variant far larger than the rest. The fix clippy wants is a `Box`, which
changes how every reader of those enums is written and puts an allocation on
the push_status path that currently has none. Worth measuring before doing,
not worth doing to silence a warning.
51 tests still pass.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,9 +17,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let cert_dir = std::path::Path::new("certs/pinned");
|
let cert_dir = std::path::Path::new("certs/pinned");
|
||||||
|
|
||||||
for printer in &mut printers {
|
for printer in &mut printers {
|
||||||
match printer {
|
if let PrinterHandle::Bambu(bambu) = printer {
|
||||||
PrinterHandle::Bambu(bambu) => report(&bambu.ensure_trusted(cert_dir)),
|
report(&bambu.ensure_trusted(cert_dir))
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,9 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT;
|
let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT;
|
||||||
loop {
|
loop {
|
||||||
if let Some(report) = bambu.print_status().await {
|
if let Some(report) = bambu.print_status().await
|
||||||
if let Some(state) = report.gcode_state.clone() {
|
&& let Some(state) = report.gcode_state.clone()
|
||||||
|
{
|
||||||
println!(" gcode_state: {state}");
|
println!(" gcode_state: {state}");
|
||||||
println!(" subtask_name: {}", report.subtask_name.clone().unwrap_or_default());
|
println!(" subtask_name: {}", report.subtask_name.clone().unwrap_or_default());
|
||||||
println!(
|
println!(
|
||||||
@@ -81,7 +82,6 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
println!(" remaining: {} min", report.mc_remaining_time.unwrap_or_default());
|
println!(" remaining: {} min", report.mc_remaining_time.unwrap_or_default());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if tokio::time::Instant::now() >= deadline {
|
if tokio::time::Instant::now() >= deadline {
|
||||||
println!(" (no gcode_state within {STATUS_TIMEOUT:?} - listing cache/ anyway)");
|
println!(" (no gcode_state within {STATUS_TIMEOUT:?} - listing cache/ anyway)");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT;
|
let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT;
|
||||||
let state = loop {
|
let state = loop {
|
||||||
if let Some(report) = bambu.print_status().await {
|
if let Some(report) = bambu.print_status().await
|
||||||
if let Some(state) = report.gcode_state.clone() {
|
&& let Some(state) = report.gcode_state.clone()
|
||||||
|
{
|
||||||
break state;
|
break state;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if tokio::time::Instant::now() >= deadline {
|
if tokio::time::Instant::now() >= deadline {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"no print.push_status with a gcode_state within {STATUS_TIMEOUT:?} - refusing to \
|
"no print.push_status with a gcode_state within {STATUS_TIMEOUT:?} - refusing to \
|
||||||
|
|||||||
@@ -230,11 +230,11 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
async fn wait_for_state(bambu: &continuum_proxy::printer::BambuPrinter) -> anyhow::Result<String> {
|
async fn wait_for_state(bambu: &continuum_proxy::printer::BambuPrinter) -> anyhow::Result<String> {
|
||||||
let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT;
|
let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT;
|
||||||
loop {
|
loop {
|
||||||
if let Some(report) = bambu.print_status().await {
|
if let Some(report) = bambu.print_status().await
|
||||||
if let Some(state) = report.gcode_state.clone() {
|
&& let Some(state) = report.gcode_state.clone()
|
||||||
|
{
|
||||||
return Ok(state);
|
return Ok(state);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if tokio::time::Instant::now() >= deadline {
|
if tokio::time::Instant::now() >= deadline {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"no print.push_status with a gcode_state within {STATUS_TIMEOUT:?} - refusing to \
|
"no print.push_status with a gcode_state within {STATUS_TIMEOUT:?} - refusing to \
|
||||||
@@ -259,12 +259,12 @@ async fn watch(bambu: &continuum_proxy::printer::BambuPrinter, before: String) {
|
|||||||
tokio::time::sleep(Duration::from_millis(1500)).await;
|
tokio::time::sleep(Duration::from_millis(1500)).await;
|
||||||
|
|
||||||
if let Some(report) = bambu.print_status().await {
|
if let Some(report) = bambu.print_status().await {
|
||||||
if let Some(state) = report.gcode_state.clone() {
|
if let Some(state) = report.gcode_state.clone()
|
||||||
if state != last {
|
&& state != last
|
||||||
|
{
|
||||||
println!(" gcode_state: {last} -> {state}");
|
println!(" gcode_state: {last} -> {state}");
|
||||||
last = state;
|
last = state;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if report.print_error != last_error {
|
if report.print_error != last_error {
|
||||||
println!(" print_error: {:?} -> {:?}", last_error, report.print_error);
|
println!(" print_error: {:?} -> {:?}", last_error, report.print_error);
|
||||||
last_error = report.print_error;
|
last_error = report.print_error;
|
||||||
@@ -274,12 +274,12 @@ async fn watch(bambu: &continuum_proxy::printer::BambuPrinter, before: String) {
|
|||||||
println!(" subtask_name: '{last_task}' -> '{task}'");
|
println!(" subtask_name: '{last_task}' -> '{task}'");
|
||||||
last_task = task;
|
last_task = task;
|
||||||
}
|
}
|
||||||
if let Some(hms) = &report.hms {
|
if let Some(hms) = &report.hms
|
||||||
if !hms.is_empty() {
|
&& !hms.is_empty()
|
||||||
|
{
|
||||||
println!(" hms (printer alerts): {}", serde_json::to_string(hms).unwrap_or_default());
|
println!(" hms (printer alerts): {}", serde_json::to_string(hms).unwrap_or_default());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
println!(" final state: {last}");
|
println!(" final state: {last}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,11 +65,11 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let only: Option<String> = std::env::args().nth(1);
|
let only: Option<String> = std::env::args().nth(1);
|
||||||
|
|
||||||
for printer in &mut printers {
|
for printer in &mut printers {
|
||||||
if let Some(id) = &only {
|
if let Some(id) = &only
|
||||||
if &printer.base().id != id {
|
&& &printer.base().id != id
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let PrinterHandle::Bambu(bambu) = printer else {
|
let PrinterHandle::Bambu(bambu) = printer else {
|
||||||
println!("skipping {} - not a Bambu printer", printer.display_name());
|
println!("skipping {} - not a Bambu printer", printer.display_name());
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -61,9 +61,8 @@ async fn main() {
|
|||||||
// cache) - none of these connected above (fake IPs), so it's always
|
// cache) - none of these connected above (fake IPs), so it's always
|
||||||
// `None`, but the point is the downcast, not a live reading.
|
// `None`, but the point is the downcast, not a live reading.
|
||||||
for printer in &fleet {
|
for printer in &fleet {
|
||||||
match printer {
|
if let PrinterHandle::Bambu(bambu) = printer {
|
||||||
PrinterHandle::Bambu(bambu) => println!(" {}: cached print_status = {:?}", bambu.sn, bambu.print_status().await),
|
println!(" {}: cached print_status = {:?}", bambu.sn, bambu.print_status().await)
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let printers = fleet::load(std::path::Path::new("printers.toml"))?;
|
let printers = fleet::load(std::path::Path::new("printers.toml"))?;
|
||||||
|
|
||||||
for printer in &printers {
|
for printer in &printers {
|
||||||
match printer {
|
if let PrinterHandle::Bambu(bambu) = printer {
|
||||||
PrinterHandle::Bambu(bambu) => report(bambu.base().name.as_str(), bambu.test_tls_handshake()),
|
report(bambu.base().name.as_str(), bambu.test_tls_handshake())
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
//! continuum-schemas for continuum.v1, which is a schema we designed
|
//! continuum-schemas for continuum.v1, which is a schema we designed
|
||||||
//! ourselves and that both TS and Rust genuinely need.
|
//! ourselves and that both TS and Rust genuinely need.
|
||||||
//!
|
//!
|
||||||
//! One file per Bambu *category* (`get_version.rs` for "info", `pushall.rs`
|
//! One file per Bambu *category* (`get_version.rs` for "info",
|
||||||
//! + `print.rs` for "pushing"/"print" - see below for why those are two
|
//! `pushall.rs` + `print.rs` for "pushing"/"print" - see below for why
|
||||||
//! files, not one). Copy `get_version.rs`'s shape for your next command.
|
//! those are two files, not one). Copy `get_version.rs`'s shape for your
|
||||||
|
//! next command.
|
||||||
//!
|
//!
|
||||||
//! Mirrors continuum-schemas' `schemas/bambulab/` JSON Schemas - same
|
//! Mirrors continuum-schemas' `schemas/bambulab/` JSON Schemas - same
|
||||||
//! category split, same "print vs pushing" correction (see that
|
//! category split, same "print vs pushing" correction (see that
|
||||||
|
|||||||
@@ -207,9 +207,9 @@ pub struct AmsUnit {
|
|||||||
pub info: Option<String>,
|
pub info: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A tray slot is either empty (just `id`) or loaded (the full field set)
|
/// A tray slot is either empty (just `id`) or loaded (the full field set) -
|
||||||
/// - two genuinely different shapes, not one shape with optional fields,
|
/// two genuinely different shapes, not one shape with optional fields, so
|
||||||
/// so this is an untagged enum rather than a struct full of `Option<T>`.
|
/// this is an untagged enum rather than a struct full of `Option<T>`.
|
||||||
/// `#[serde(deny_unknown_fields)]` on `Empty` is load-bearing: untagged
|
/// `#[serde(deny_unknown_fields)]` on `Empty` is load-bearing: untagged
|
||||||
/// enums try variants in order, and without it a *loaded* tray (which has
|
/// enums try variants in order, and without it a *loaded* tray (which has
|
||||||
/// every field `Empty` allows, plus more) would incorrectly match `Empty`
|
/// every field `Empty` allows, plus more) would incorrectly match `Empty`
|
||||||
|
|||||||
+11
-11
@@ -162,15 +162,15 @@ impl PrintStatusCache {
|
|||||||
// the next one that did looked like it had skipped ahead. That is now
|
// the next one that did looked like it had skipped ahead. That is now
|
||||||
// reported where it happens (see `handle_incoming_report`), which
|
// reported where it happens (see `handle_incoming_report`), which
|
||||||
// leaves this warning meaning what it says.
|
// leaves this warning meaning what it says.
|
||||||
if let (Some(last), Some(incoming_seq), false) = (self.last_sequence_id, incoming_seq, is_full_object) {
|
if let (Some(last), Some(incoming_seq), false) = (self.last_sequence_id, incoming_seq, is_full_object)
|
||||||
if incoming_seq != last.wrapping_add(1) {
|
&& incoming_seq != last.wrapping_add(1)
|
||||||
|
{
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"print.push_status sequence gap: expected {}, got {incoming_seq} - the in-memory \
|
"print.push_status sequence gap: expected {}, got {incoming_seq} - the in-memory \
|
||||||
object may be missing whatever changed in between",
|
object may be missing whatever changed in between",
|
||||||
last.wrapping_add(1)
|
last.wrapping_add(1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let Some(incoming_seq) = incoming_seq {
|
if let Some(incoming_seq) = incoming_seq {
|
||||||
self.last_sequence_id = Some(incoming_seq);
|
self.last_sequence_id = Some(incoming_seq);
|
||||||
}
|
}
|
||||||
@@ -305,17 +305,17 @@ impl BambuMqttSession {
|
|||||||
/// whose `sequence_id` matches the one this call sent.
|
/// whose `sequence_id` matches the one this call sent.
|
||||||
///
|
///
|
||||||
/// This crate tried adding its own correlation field
|
/// This crate tried adding its own correlation field
|
||||||
/// (`continuum_correlation_id`) instead of relying on `sequence_id`,
|
/// (`continuum_correlation_id`) instead of relying on `sequence_id`, on
|
||||||
/// on the understanding that extra fields survive into most replies.
|
/// the understanding that extra fields survive into most replies.
|
||||||
/// Confirmed live that this doesn't hold for `get_version` specifically
|
/// Confirmed live that this doesn't hold for `get_version`
|
||||||
/// - a real H2C's reply had exactly `["command", "module",
|
/// specifically - a real H2C's reply had exactly `["command", "module",
|
||||||
/// "sequence_id"]`, nothing extra at all, so the correlation field
|
/// "sequence_id"]`, nothing extra at all, so the correlation field
|
||||||
/// never came back and every `get_version` call just timed out.
|
/// never came back and every `get_version` call just timed out.
|
||||||
/// `sequence_id` is what's actually proven to round-trip for it
|
/// `sequence_id` is what's actually proven to round-trip for it
|
||||||
/// (confirmed earlier, live, on both protocol versions), so that's
|
/// (confirmed earlier, live, on both protocol versions), so that's what
|
||||||
/// what this uses. Whether a custom field survives on some *other*
|
/// this uses. Whether a custom field survives on some *other* command
|
||||||
/// command (`calibration`, say) is unverified, not confirmed false -
|
/// (`calibration`, say) is unverified, not confirmed false - this was
|
||||||
/// this was only ever checked for `get_version`.
|
/// only ever checked for `get_version`.
|
||||||
///
|
///
|
||||||
/// Not for `print.push_status` - that's not a single reply, see
|
/// Not for `print.push_status` - that's not a single reply, see
|
||||||
/// `PrintStatusCache`. Not for a command with no reply at all either,
|
/// `PrintStatusCache`. Not for a command with no reply at all either,
|
||||||
|
|||||||
+6
-5
@@ -143,11 +143,12 @@ pub trait GenericPrinter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// M106's `S` parameter is a raw 0-255 PWM value, not a percentage. Shared
|
/// M106's `S` parameter is a raw 0-255 PWM value, not a percentage. Shared
|
||||||
/// by anything that ultimately sends gcode (Bambu, PrusaLink, PrusaSerial)
|
/// by anything that ultimately sends gcode (Bambu, PrusaLink,
|
||||||
/// - *not* a trait default, since Klipper's hypothetical native fan API
|
/// PrusaSerial) - *not* a trait default, since Klipper's hypothetical
|
||||||
/// below takes a percent directly and has no use for this at all. Private,
|
/// native fan API below takes a percent directly and has no use for this at
|
||||||
/// but still visible to bambu.rs/prusa.rs: Rust's module privacy reaches
|
/// all. Private, but still visible to bambu.rs/prusa.rs: Rust's module
|
||||||
/// into child modules, not just the exact file it's defined in.
|
/// privacy reaches into child modules, not just the exact file it's defined
|
||||||
|
/// in.
|
||||||
fn percent_to_pwm(percent: u8) -> u8 {
|
fn percent_to_pwm(percent: u8) -> u8 {
|
||||||
((percent.min(100) as u16 * 255) / 100) as u8
|
((percent.min(100) as u16 * 255) / 100) as u8
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user