0

Struct

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Post<PostId, AccountId> {
    pub id: PostId,

    pub edited: bool,

    pub owner: AccountId,

    pub content: Vec<u8>,

    pub hidden: bool,

    pub upvotes_count: u32,

    pub downvotes_count: u32,


}

Declaring type

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type PostOf<T> = Post<PostId, AccountIdOf<T>>;

Writing impl gives error:

impl<T: Config> PostOf<T> {
    pub fn new(id: PostId, created_by: AccountIdOf<T>, content: Vec<u8>) -> Self {
        Post { id, edited: false, owner: created_by, content, hidden: false, upvotes_count: 0, downvotes_count: 0 }
    }
}

Error:

impl<T: Config> PostOf<T> {
  |      ^ unconstrained type parameter

1 Answer 1

1

Write:

impl<PostId, AccountId> Post<PostId, AccountId> {
    pub fn new(id: PostId, created_by: AccountId, content: Vec<u8>) -> Self {
        Post { id, edited: false, owner: created_by, content, hidden: false, upvotes_count: 0, downvotes_count: 0 }
    }
}

This will fix your compile error.

You tried to implement a type aliases, not sure if this is supported. Nevertheless, there is no need to do this here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.