randomPoison / gunship-rs

An experimental game engine written in Rust.
MIT License
27 stars 3 forks source link

Change Builders To Not Consume `self` On Each Call #63

Open randomPoison opened 8 years ago

randomPoison commented 8 years ago

Current builders in Gunship (e.g. MeshBuilder) consume the builder instance on each mutation. This works fine for chaining but makes non-chained calls a pain:

Builder::new().foo().bar().build();

let builder = Builder::new();
builder.foo();
builder.bar(); // ERROR: `builder` was consumed in the last statement.
builder.build();

This can be fixed by changing the signatures of the methods from foo(self) -> Self to foo(&mut self) -> &mut Self.

Builders that this needs to be changed for:

For more information on the builder pattern in rust see this article: https://aturon.github.io/ownership/builders.html