-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't override generics impl in proc-macros on encode impl (#354)
* fix: Don't override generics impl in proc-mac * fix: lint new bench test
- Loading branch information
Showing
3 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use rasn::prelude::*; | ||
|
||
// https://github.com/librasn/rasn/issues/193 | ||
#[test] | ||
fn test_sequence_with_generics_issue_193() { | ||
pub trait LeetTrait { | ||
type Leet: Encode + Decode + core::fmt::Debug + Clone; | ||
|
||
fn leet(&self) -> Self::Leet; | ||
} | ||
|
||
#[derive(AsnType, Encode, Decode, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
#[rasn(choice, automatic_tags)] | ||
pub enum Messages<T: LeetTrait> { | ||
Content(T::Leet), | ||
All(()), | ||
} | ||
#[derive(AsnType, Encode, Decode, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
#[rasn(delegate, automatic_tags)] | ||
pub struct Message<T: LeetTrait>(T); | ||
|
||
#[derive(AsnType, Encode, Decode, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] | ||
pub struct Hello(String); | ||
|
||
impl LeetTrait for Hello { | ||
type Leet = u16; | ||
|
||
fn leet(&self) -> Self::Leet { | ||
1337 | ||
} | ||
} | ||
|
||
let hello_message: Message<Hello> = Message(Hello("Hello".to_string())); | ||
let hello_selection: Messages<Hello> = Messages::Content(hello_message.0.leet()); | ||
|
||
let encoded = rasn::oer::encode::<Messages<Hello>>(&hello_selection).unwrap(); | ||
assert_eq!(encoded, vec![0x80, 0x05, 0x39]); | ||
assert_eq!( | ||
hello_selection, | ||
rasn::oer::decode::<Messages<Hello>>(&encoded).unwrap() | ||
) | ||
} |