diff --git a/derive/src/shared.rs b/derive/src/shared.rs index f5ddb2c..aa4948e 100644 --- a/derive/src/shared.rs +++ b/derive/src/shared.rs @@ -73,7 +73,7 @@ pub(crate) fn struct_bounds_strings(struct_: &Struct, bound_name: &str) -> (Stri return ("".to_string(), "".to_string()); } let mut generic_w_bounds = "<".to_string(); - for generic in generics.iter() { + for generic in generics.iter().filter(|g| g.ident_only() != "Self") { generic_w_bounds += generic .full_with_const(&[format!("nanoserde::{}", bound_name).as_str()], true) .as_str(); @@ -82,7 +82,7 @@ pub(crate) fn struct_bounds_strings(struct_: &Struct, bound_name: &str) -> (Stri generic_w_bounds += ">"; let mut generic_no_bounds = "<".to_string(); - for generic in generics.iter() { + for generic in generics.iter().filter(|g| g.ident_only() != "Self") { generic_no_bounds += generic.ident_only().as_str(); generic_no_bounds += ", "; } @@ -97,7 +97,7 @@ pub(crate) fn enum_bounds_strings(enum_: &Enum, bound_name: &str) -> (String, St return ("".to_string(), "".to_string()); } let mut generic_w_bounds = "<".to_string(); - for generic in generics.iter() { + for generic in generics.iter().filter(|g| g.ident_only() != "Self") { generic_w_bounds += generic .full_with_const(&[format!("nanoserde::{}", bound_name).as_str()], true) .as_str(); @@ -106,7 +106,7 @@ pub(crate) fn enum_bounds_strings(enum_: &Enum, bound_name: &str) -> (String, St generic_w_bounds += ">"; let mut generic_no_bounds = "<".to_string(); - for generic in generics.iter() { + for generic in generics.iter().filter(|g| g.ident_only() != "Self") { generic_no_bounds += generic.ident_only().as_str(); generic_no_bounds += ", "; } diff --git a/tests/bin.rs b/tests/bin.rs index d3d88da..355c020 100644 --- a/tests/bin.rs +++ b/tests/bin.rs @@ -119,6 +119,30 @@ fn field_proxy() { assert!(test == test_deserialized); } +#[test] +fn field_ignore_self_bound() { + #[derive(SerBin)] + pub struct Serializable<'a> + where + Self: 'a, + { + foo: &'a i32, + } + + #[derive(DeBin)] + pub struct DeSerializable { + foo: i32, + } + + let foo_base = 42; + + let test = Serializable { foo: &42 }; + + let bytes = SerBin::serialize_bin(&test); + let deser: DeSerializable = DeBin::deserialize_bin(&bytes).unwrap(); + assert_eq!(foo_base, deser.foo); +} + #[test] fn struct_proxy() { #[derive(PartialEq, Debug)]