Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive magic from Component forces traits to be implemented #301

Closed
ftupas opened this issue May 11, 2023 · 1 comment · Fixed by #302
Closed

derive magic from Component forces traits to be implemented #301

ftupas opened this issue May 11, 2023 · 1 comment · Fixed by #302
Assignees

Comments

@ftupas
Copy link
Contributor

ftupas commented May 11, 2023

Context

Currently, these traits are implemented on each Component (see https://github.com/dojoengine/dojo/blob/main/crates/dojo-lang/src/component.rs#L82)

    builder.add_modified(RewriteNode::interpolate_patched(
        "
            #[derive(Copy, Drop, Serde)]
            struct $type_name$ {
                $members$
            }
   ...

This forces the type to have these implementations even when some of its members cannot have a certain trait. For example we have a Foo component that has a Felt252Dict<u8> for one of its members.

#[derive(Component)]
struct Foo {
    foo: Felt252Dict<u8>
}

As shown below, this results in an error by the compiler it contains a dictionary and it cannot be copied

error: Invalid copy trait implementation, Trait has no implementation in context: core::traits::Copy::<core::dict::Felt252Dict::<core::felt252>>
 --> impls:1:1
impl FooCopy of Copy::<Foo>;
^**************************^

Possible solutions

  • Remove this derive magic and have developers explicitly derive traits
  • Keep Component abstraction and add a CustomComponent that developers can opt into if they want to have custom traits implemented
@ftupas
Copy link
Contributor Author

ftupas commented May 11, 2023

I would like to take this, can anyone please assign it to me? 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant