Change LocationOptions to use alternative non_exhaustive impl (fixes #29)

As per Rust RFC 2008: https://rust-lang.github.io/rfcs/2008-non-exhaustive.html,
this is the recommended approach to applying non-exhaustive functionality
to a struct currently. Previously, external crates would not be able to use
`LocationOptions { source: Some("foo".into()), ..Default::default() };`,
making it annoying to use.

This change allows functional record update patterns for external crates.
This commit is contained in:
Rob Wagner 2025-06-04 18:23:30 -04:00
parent 4eae8b3fe2
commit 8ba234b9b3
No known key found for this signature in database
GPG key ID: 53CCB4497B15CF61

View file

@ -113,7 +113,6 @@ impl IntoResponseParts for HxLocation {
#[cfg(feature = "serde")]
#[cfg_attr(feature = "unstable", doc(cfg(feature = "serde")))]
#[derive(Debug, Clone, serde::Serialize, Default)]
#[non_exhaustive]
pub struct LocationOptions {
/// The source element of the request.
#[serde(skip_serializing_if = "Option::is_none")]
@ -136,6 +135,10 @@ pub struct LocationOptions {
/// Headers to submit with the request.
#[serde(skip_serializing_if = "Option::is_none")]
pub headers: Option<serde_json::Value>,
// Hacky way of making this struct non-exhaustive.
// See <https://rust-lang.github.io/rfcs/2008-non-exhaustive.html#functional-record-updates> and <https://github.com/robertwayne/axum-htmx/issues/29> for reasoning.
#[serde(skip)]
pub non_exhaustive: (),
}
#[cfg(feature = "serde")]
@ -150,6 +153,7 @@ impl LocationOptions {
swap: None,
values: None,
headers: None,
non_exhaustive: (),
} = self
else {
return false;