mirror of
https://github.com/robertwayne/axum-htmx
synced 2025-12-18 13:45:17 +01:00
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:
parent
4eae8b3fe2
commit
8ba234b9b3
1 changed files with 5 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue