buildstructor icon indicating copy to clipboard operation
buildstructor copied to clipboard

Support free functions

Open BrynCooke opened this issue 2 years ago • 2 comments

Maybe we can support functions that are not on an impl

Alternative 1:

Directly on fn outside of impl.

#[builder(entry="foo", exit="call")
fn do_foo(a: usize) {
...
}

Alternative 2:

Still require an impl. Allow derivation of proxy method:

#[buildstructor::buildstructor]
impl Foo {
  #[builder(entry="foo", exit="call", proxy=true)
  fn do_foo(a: usize) {
  ...
  }
}

//Derived
fn foo() {
  Foo::foo()
}

BrynCooke avatar May 14 '22 07:05 BrynCooke

While using bevy_ecs, I want to add entities that has different sets of components attached to them. This means that what I'd ideally want, is a way to construct a builder, around a function, but the resulting struct should atleast derive(Bundle).

CGMossa avatar Jul 13 '22 15:07 CGMossa

@CGMossa Could you elaborate a bit more? The final struct that a buildstructor builder spits out is not derived, it is the result of a constructor being called. Thus you can put derives on that struct no problem. Probably some code examples would help me understand.

BrynCooke avatar Jul 17 '22 21:07 BrynCooke