Skip to content

Commit

Permalink
Code revisions for #98
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Jan 20, 2025
1 parent 9fd4386 commit 0eeff5c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
67 changes: 33 additions & 34 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,49 +216,48 @@ pub fn implement_for_unnamed(field: &Field, params: &GenParams) -> TokenStream2
match attr {
// Generate nothing for skipped field
Some(meta) if meta.path().is_ident("skip") => quote! {},
Some(_) => match params.mode {
GenMode::Get => {
let fn_name = Ident::new("get", Span::call_site());
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&self) -> &#ty {
&self.0
Some(_) => {
let fn_name = Ident::new(params.mode.name(), Span::call_site());
match params.mode {
GenMode::Get => {
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&self) -> &#ty {
&self.0
}
}
}
}
GenMode::GetCopy => {
let fn_name = Ident::new("get", Span::call_site());
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&self) -> #ty {
self.0
GenMode::GetCopy => {
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&self) -> #ty {
self.0
}
}
}
}
GenMode::Set => {
let fn_name = Ident::new("set", Span::call_site());
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&mut self, val: #ty) -> &mut Self {
self.0 = val;
self
GenMode::Set => {
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&mut self, val: #ty) -> &mut Self {
self.0 = val;
self
}
}
}
}
GenMode::GetMut => {
let fn_name = Ident::new("get_mut", Span::call_site());
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&mut self) -> &mut #ty {
&mut self.0
GenMode::GetMut => {
quote! {
#(#doc)*
#[inline(always)]
#visibility fn #fn_name(&mut self) -> &mut #ty {
&mut self.0
}
}
}
}
},
}
None => quote! {},
}
}
4 changes: 2 additions & 2 deletions tests/unary_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_unary_tuple() {
struct CopyUnaryTuple(#[getset(get_copy)] i32);

let tup = CopyUnaryTuple(42);
assert_eq!(tup.get(), 42);
assert_eq!(tup.get_copy(), 42);
}

#[test]
Expand All @@ -35,5 +35,5 @@ fn test_unary_tuple_with_attrs() {
struct CopyUnaryTuple(i32);

let tup = CopyUnaryTuple(42);
assert_eq!(tup.get(), 42);
assert_eq!(tup.get_copy(), 42);
}

0 comments on commit 0eeff5c

Please sign in to comment.