don't generate default with getter
This commit is contained in:
parent
0e59545f92
commit
903a3c7589
@ -39,6 +39,7 @@ impl ConfigField {
|
||||
|
||||
pub(crate) fn helper(&self, attrs: &[syn::Attribute]) -> (Option<TokenStream>, syn::Type) {
|
||||
if self.needs_newtype() {
|
||||
let default = self.helper_default();
|
||||
let derives = attrs
|
||||
.iter()
|
||||
.find(|attr| attr.path().is_ident("derive"))
|
||||
@ -50,7 +51,7 @@ impl ConfigField {
|
||||
derive.contains("Tree")
|
||||
|| derive.contains("Serialize")
|
||||
|| derive.contains("Deserialize")
|
||||
|| (self.default.is_some() && derive.contains("Default"))
|
||||
|| (default.is_some() && derive.contains("Default"))
|
||||
}) == Some(false)
|
||||
});
|
||||
quote! {#[derive(#(#derives,)*)]}
|
||||
@ -60,7 +61,6 @@ impl ConfigField {
|
||||
let ty = &self.ty;
|
||||
|
||||
let new = self.helper_new();
|
||||
let default = self.helper_default();
|
||||
let serde = self.helper_serde();
|
||||
let tree = self.helper_tree();
|
||||
|
||||
@ -153,6 +153,9 @@ impl ConfigField {
|
||||
}
|
||||
|
||||
pub(crate) fn helper_default(&self) -> Option<TokenStream> {
|
||||
if self.typ.is_some() {
|
||||
return None;
|
||||
}
|
||||
self.default.as_ref().map(|default| {
|
||||
let ident = self.helper_ident();
|
||||
let default_default = parse_quote!(::core::default::Default::default());
|
||||
|
@ -28,6 +28,17 @@ struct Config {
|
||||
field: Cell<i32>,
|
||||
}
|
||||
|
||||
#[config]
|
||||
struct WithSetterAndDefault {
|
||||
#[config(
|
||||
default = "42",
|
||||
typ = "i32",
|
||||
get = "Cell::get",
|
||||
set = "set_cell::<{i32::MIN}, {i32::MAX}>"
|
||||
)]
|
||||
field: Cell<i32>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get() {
|
||||
let mut buffer = [0u8; 32];
|
||||
|
Loading…
Reference in New Issue
Block a user