Skip to content

Commit

Permalink
Merge branch 'phsym-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Glotfelty committed Jan 12, 2025
2 parents 4beb2c9 + 96fa148 commit 1e6928c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion strum_macros/src/macros/enum_try_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn enum_try_as_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
syn::Fields::Unnamed(values) => {
let variant_name = &variant.ident;
let types: Vec<_> = values.unnamed.iter().map(|field| {
field.to_token_stream()
field.ty.to_token_stream()
}).collect();
let field_names: Vec<_> = values.unnamed.iter().enumerate().map(|(i, _)| {
let name = "x".repeat(i + 1);
Expand Down
7 changes: 7 additions & 0 deletions strum_tests/tests/enum_try_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum Foo {
Unnamed0(),
Unnamed1(u128),
Unnamed2(bool, String),
Unnamed3(#[allow(deprecated)] u128),
#[strum(disabled)]
#[allow(dead_code)]
Disabled(u32),
Expand Down Expand Up @@ -35,6 +36,12 @@ fn unnamed_2() {
assert_eq!(Some((true, String::from("Hay"))), foo.try_as_unnamed_2());
}

#[test]
fn unnamed_3() {
let foo = Foo::Unnamed3(128);
assert_eq!(Some(&128), foo.try_as_unnamed_3_ref());
}

#[test]
fn can_mutate() {
let mut foo = Foo::Unnamed1(128);
Expand Down

0 comments on commit 1e6928c

Please sign in to comment.