Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion derive/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn quote(
let index = utils::variant_index(v, i);

let create = create_instance(
quote! { #type_name #type_generics :: #name },
quote! { #type_name :: #name #type_generics },
&format!("{}::{}", type_name, name),
input,
&v.fields,
Expand Down
28 changes: 28 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::borrow::Cow;

use parity_scale_codec::{
Compact, CompactAs, Decode, DecodeWithMemTracking, Encode, EncodeAsRef, Error, HasCompact,
Output,
Expand Down Expand Up @@ -941,3 +943,29 @@ fn non_literal_variant_discriminant() {
B = A + 1,
}
}

#[test]
fn derive_decode_for_enum_with_lifetime_param_and_struct_like_variant() {
// An enum that has a lifetime parameter and a struct-like variant.
#[derive(PartialEq, Eq, Debug, DeriveDecode, DeriveEncode)]
enum Enum<'a> {
StructLike { val: u8 },
// For completeness, also check a struct-like variant that actually uses the lifetime,
// as well as the corresponding tuple-like variants.
StructLikeCow { val: Cow<'a, u8> },
TupleLike(u8),
TupleLikeCow(Cow<'a, u8>),
}

let val = 123;
let objs = vec![
Enum::StructLike { val: 234 },
Enum::StructLikeCow { val: Cow::Borrowed(&val) },
Enum::TupleLike(234),
Enum::TupleLikeCow(Cow::Borrowed(&val)),
];

let data = objs.encode();
let objs_d = Vec::<Enum>::decode(&mut &data[..]).unwrap();
assert_eq!(objs_d, objs);
}
Loading