Skip to content

refactor(eventhubs)!: harden public API for 1.0 (non_exhaustive + TryFrom)#4722

Draft
j7nw4r wants to merge 1 commit into
Azure:mainfrom
j7nw4r:j7nw4r/eventhubs-api-hardening-1.0
Draft

refactor(eventhubs)!: harden public API for 1.0 (non_exhaustive + TryFrom)#4722
j7nw4r wants to merge 1 commit into
Azure:mainfrom
j7nw4r:j7nw4r/eventhubs-api-hardening-1.0

Conversation

@j7nw4r

@j7nw4r j7nw4r commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

This is a BREAKING change to azure_messaging_eventhubs, intended to land before the 1.0.0 API freeze. It marks the crate's public data, options, and error types #[non_exhaustive] and converts four panicking MessageId conversions from From to TryFrom. Neither change can be made after 1.0 without a major version bump, so they are grouped here as pre-1.0 hardening.

Motivation

#[non_exhaustive] lets new fields and enum variants be added after 1.0 without breaking downstream code, which is not possible once the public surface is frozen. The four From<MessageId> impls that produced Uuid, Vec<u8>, String, and u64 panicked whenever the MessageId variant did not match the requested target type, putting a panic on an infallible-looking conversion in the public API; TryFrom surfaces the mismatch as a recoverable error instead.

Changes

  • Added #[non_exhaustive] to the MessageId, StartLocation, and ProcessorStrategy enums; the SendBatchOptions, SendEventOptions, SendMessageOptions, AddEventDataOptions, EventDataBatchOptions, OpenReceiverOptions, StartPosition, and RetryOptions options structs; and the EventHubProperties, EventHubPartitionProperties, Checkpoint, Ownership, StartPositions, and EventHubsError data structs. ErrorKind and ConnectionString already had it.
  • Added a Default derive to AddEventDataOptions so external code keeps a construction path now that the empty struct literal is no longer usable outside the crate. The other affected structs already derived or implemented Default.
  • Changed Uuid, Vec<u8>, String, and u64 to implement TryFrom<MessageId> (with Error = EventHubsError) instead of From<MessageId>. The error reuses the crate's existing EventHubsError type to keep the public error surface unified. The infallible conversions into MessageId, and between MessageId and AmqpMessageId, remain From.
  • Updated the crate's doc examples (including the README rendered into the crate docs), integration tests, examples, and benchmark to construct the now-non_exhaustive structs via Default::default() plus public-field assignment, since struct-literal and functional-record-update construction and exhaustive enum matching are no longer available to external code.
  • Recorded both breaking changes under ## 0.15.0 (Unreleased) in the CHANGELOG.

Validation

  • cargo build -p azure_messaging_eventhubs --all-features: pass
  • cargo clippy -p azure_messaging_eventhubs --all-targets --all-features -- -D warnings: pass
  • cargo test -p azure_messaging_eventhubs --all-features: pass (offline unit and doc tests; live #[recorded::test(live)] tests self-skip without credentials)
  • cargo fmt -p azure_messaging_eventhubs -- --check: clean

…From)

These are deliberate breaking changes intended to land before the 1.0.0
API freeze, since they cannot be made afterward without a major bump.

Mark the crate's public data, options, and error types
`#[non_exhaustive]` so fields and variants can be added post-1.0 without
breaking downstream code: the `MessageId`, `StartLocation`, and
`ProcessorStrategy` enums; the `SendBatchOptions`, `SendEventOptions`,
`SendMessageOptions`, `AddEventDataOptions`, `EventDataBatchOptions`,
`OpenReceiverOptions`, `StartPosition`, and `RetryOptions` options
structs; and the `EventHubProperties`, `EventHubPartitionProperties`,
`Checkpoint`, `Ownership`, `StartPositions`, and `EventHubsError` data
structs. `AddEventDataOptions` gains a `Default` derive so external code
retains a construction path.

Convert the four panicking `MessageId` conversions from `From` to
`TryFrom`. `Uuid`, `Vec<u8>`, `String`, and `u64` now implement
`TryFrom<MessageId>` returning `Result<_, EventHubsError>` instead of a
`From` impl that panicked on a non-matching variant. The infallible
conversions into `MessageId`, and between `MessageId` and
`AmqpMessageId`, are unchanged.

Update the crate's doc examples, tests, examples, and benchmark to
construct the now-non_exhaustive structs via `Default::default()` plus
public-field assignment, and record both changes in the CHANGELOG.
@j7nw4r
j7nw4r force-pushed the j7nw4r/eventhubs-api-hardening-1.0 branch from 82258b9 to 8488f3a Compare July 8, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant