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

Introduce StructImplementation and associated methods #5912

Closed
Thunkar opened this issue Sep 4, 2024 · 2 comments
Closed

Introduce StructImplementation and associated methods #5912

Thunkar opened this issue Sep 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Thunkar
Copy link
Contributor

Thunkar commented Sep 4, 2024

Problem

Currently there's only StructDefinition. Sometimes it is useful to manipulate a struct's impl, much like TraitImplementation (mostly to add methods).

Happy Case

Something like this can be done:

comptime fn get_imp(s: StructDefinition) {
  let implementation = s.get_impl();
  let methods = implementation.methods();
  let new_method = ...;
  implementation.set_methods(methods.push_back(new_method));
}

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

Blocker

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@Thunkar Thunkar added the enhancement New feature or request label Sep 4, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 4, 2024
@jfecher
Copy link
Contributor

jfecher commented Sep 4, 2024

Sometimes it is useful to manipulate a struct's impl, much like TraitImplementation (mostly to add methods).

I think this use case may be covered by allowing unquoting impls at top-level once #5927 is merged:

comptime fn get_imp(s: StructDefinition) -> Quoted {
  let t = s.as_type();
  let generics = s.generics()
    .map(|g| quote { $g })
    .join(quote {,});

  quote {
      impl<$generics> $t {
          pub fn my_new_method(self) { ... }
      }
  }
}

@asterite
Copy link
Collaborator

asterite commented Sep 5, 2024

Fixed by #5927

@asterite asterite closed this as completed Sep 5, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

3 participants