Skip to content

Commit

Permalink
Add doc comments for Unwrap, IsVariant (#179)
Browse files Browse the repository at this point in the history
Prevents a linting issue from `missing_docs` on the derived functions

Solves #159

Co-authored-by: Jelte Fennema <github-tech@jeltef.nl>
  • Loading branch information
Technohacker and JelteF authored Feb 8, 2022
1 parent 8e16178 commit 9e8582b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/is_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
Fields::Unnamed(_) => quote! { (..) },
Fields::Unit => quote! {},
};
let variant_name = stringify!(variant_ident);
let func = quote! {
#[doc = "Returns `true` if this value is of type `"]
#[doc = #variant_name]
#[doc = "`. Returns `false` otherwise"]
pub fn #fn_name(&self) -> bool {
match self {
#enum_name ::#variant_ident #data_pattern => true,
Expand Down
4 changes: 4 additions & 0 deletions src/unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
} else {
quote! {}
};
let variant_name = stringify!(variant_ident);
let func = quote! {
#track_caller
#[doc = "Unwraps this value to the `"]
#[doc = #variant_name]
#[doc = "` variant\n\nPanics if this value is of any other type"]
pub fn #fn_name(self) -> #ret_type {
match self {
#enum_name ::#variant_ident #data_pattern => #ret_value,
Expand Down

0 comments on commit 9e8582b

Please sign in to comment.