Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(is_variant): add #[must_use] annotation #350

Merged
merged 10 commits into from
Apr 19, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- The `Constructor` and `IsVariant` derives now generate `const fn` functions.
- Static methods derived by `IsVariant` are now marked `#[must_use]`.
tyranron marked this conversation as resolved.
Show resolved Hide resolved
- The `Unwrap` and `IsVariant` derives now generate doc comments.
- `#[automatically_derived]` is now emitted from all macro expansions. This
should prevent code style linters from attempting to modify the generated
Expand Down
8 changes: 6 additions & 2 deletions impl/doc/is_variant.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ The derive in the above example code generates the following code:
# Nothing
# }
impl <T> Maybe<T>{
#[inline]
#[must_use]
pub const fn is_just(&self) -> bool {
tyranron marked this conversation as resolved.
Show resolved Hide resolved
match self {Self::Just(..) => true, _ => false}
matches!(self, Self::Just(..))
}
#[inline]
#[must_use]
pub const fn is_nothing(&self) -> bool {
match self {Self::Nothing => true, _ => false}
matches!(self, Self::Nothing)
}
}
```
6 changes: 2 additions & 4 deletions impl/src/is_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
#[doc = #variant_name]
#[doc = "`. Returns `false` otherwise"]
#[inline]
#[must_use]
pub const fn #fn_name(&self) -> bool {
match self {
#enum_name ::#variant_ident #data_pattern => true,
_ => false
}
matches!(self, #enum_name ::#variant_ident #data_pattern)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For hygiene, this should be used like derive_more::core::matches!.

}
};
funcs.push(func);
Expand Down