Closed Nicceboy closed 1 week ago
Huh, the first code should work.
Huh, the first code should work.
It seems to work when newtype style is used, for example
#[derive(AsnType, Debug, Decode, Encode, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(automatic_tags)]
pub struct ContributedExtensionBlocks<T: ContributedExtension>(
SequenceOf<ContributedExtensionBlock<T>>,
);
Edit, nevermind, it won't. The compiler error was just hidden by other errors.
@Nicceboy Is this still the case?
Yeah, the commented in the following does not compile:
use rasn::prelude::*;
pub trait TestTrait: Encode + Decode + AsnType {
type Req: Encode + Decode + AsnType;
}
#[derive(AsnType, Encode, Decode, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct Hello(String);
// #[derive(AsnType, Encode, Decode, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
// #[rasn(choice, automatic_tags)]
// pub enum TraitNotCarried<T: TestTrait> {
// Maybe(T::Req),
// MaybeNot(()),
// }
impl TestTrait for Hello {
type Req = u8;
}
#[derive(AsnType, Encode, Decode, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(choice, automatic_tags)]
pub enum TraitNotCarried<T>
where
T: TestTrait,
{
Maybe(T::Req),
MaybeNot(()),
}
fn main() {
let hello = Hello("world!".to_string());
println!("{}", hello.0);
}
It seems that syntax matters for declaring generics and trait declarations.
I have the following struct:
It does not compile, and if I expand
Encode
macro for example,CertExtType
condition is not carried.However, if I change syntax to following
Correct macro code is generated. I almost ended up writing custom functions, but noticed by accident. If someone else fights the same problem 😁 .