axum-htmx icon indicating copy to clipboard operation
axum-htmx copied to clipboard

Use hidden field rather than non_exaustive for Options to support update syntax

Open ColonelThirtyTwo opened this issue 7 months ago • 2 comments

In current Rust, using #[non_exhaustive] on a structure prevents using the structure update syntax:

let options = LocationOptions {
    target: Some("foo".into()),
    ..Default::default()
};
error[E0639]: cannot create non-exhaustive struct using struct expression

This is documented in the RFC that added the attribute.

This limitation makes the *Options structures annoying to use. I suggest using a hidden _non_exhaustive: () field in them until Rust supports the structure update syntax with the #[non_exhaustive] attribute.

ColonelThirtyTwo avatar Apr 24 '25 14:04 ColonelThirtyTwo

I hadn't realized that this would cause that issue in downstream code, but it makes sense after reading through that link.

The proposed change makes sense. If you'd like to make a PR, I'd be happy to accept it. Otherwise, I'll address this sometime this weekend.

robertwayne avatar Apr 25 '25 16:04 robertwayne

Yeah, honestly I was surprised that #[non_exhaustive] had that limitation. It's pretty restrictive.

ColonelThirtyTwo avatar Apr 28 '25 14:04 ColonelThirtyTwo