Skip to content

Conversation

@smaeul
Copy link
Contributor

@smaeul smaeul commented Nov 17, 2025

Since the packet ID is optional in a PUBLISH packet depending on the QoS, adapter functions that construct a PUBLISH packet may need to conditionally insert a packet ID. With the current builder method, this is not ergonomic -- the user must create a mutable binding for the builder and conditionally call the packet_id() method. By changing the method to take an Option, the user can unconditionally call the method and avoid interrupting the builder pattern. See the simplification in examples/publish.rs as an example.

This is a suggestion for a minor API change. It makes certain use cases nicer to implement (mine looks similar to the example, adapting from another library that generates MQTT messages at multiple QoS levels), but maybe the extra Some is not as nice when the QoS is known at compile time. An alternative would be to a new method that takes the Option.

Since the packet ID is optional in a PUBLISH packet depending on the
QoS, adapter functions that construct a PUBLISH packet may need to
conditionally insert a packet ID. With the current builder method, this
is not ergonomic -- the user must create a mutable binding for the
builder and conditionally call the `packet_id()` method. By changing the
method to take an Option, the user can unconditionally call the method
and avoid interrupting the builder pattern. See the simplification in
`examples/publish.rs` as an example.
@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.90%. Comparing base (609c3a3) to head (e395594).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #50   +/-   ##
=======================================
  Coverage   90.90%   90.90%           
=======================================
  Files          55       55           
  Lines        7456     7456           
=======================================
  Hits         6778     6778           
  Misses        678      678           
Files with missing lines Coverage Δ
src/mqtt/packet/v3_1_1/publish.rs 95.74% <100.00%> (ø)
src/mqtt/packet/v5_0/publish.rs 94.48% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redboltz
Copy link
Owner

I understand your requirement. However, this PR introduces a breaking change.
I want to minimize the impact on existing code. What do you think about #53?

@smaeul
Copy link
Contributor Author

smaeul commented Nov 18, 2025

Closing in favor of #53

@smaeul smaeul closed this Nov 18, 2025
@smaeul smaeul deleted the up/option-packet_id branch November 18, 2025 04:28
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