summaryrefslogtreecommitdiff
path: root/engine/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/util.rs')
-rw-r--r--engine/src/util.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/engine/src/util.rs b/engine/src/util.rs
index b1a98ca..a7d5794 100644
--- a/engine/src/util.rs
+++ b/engine/src/util.rs
@@ -22,3 +22,60 @@ macro_rules! or {
}
pub(crate) use or;
+
+macro_rules! builder {
+ (
+ $(#[doc = $doc: literal])*
+ #[builder(
+ name = $builder_name: ident
+ $(, derives = ($($builder_derive: ident),+))?
+ )]
+ $(#[$attr: meta])*
+ $visibility: vis struct $name: ident
+ {
+ $(
+ $(#[$field_attr: meta])*
+ $field_visibility: vis $field: ident: $field_type: ty,
+ )*
+ }
+ ) => {
+ $(#[doc = $doc])*
+ $(#[$attr])*
+ $visibility struct $name
+ {
+ $(
+ $(#[$field_attr])*
+ $field_visibility $field: $field_type,
+ )*
+ }
+
+ $(#[derive($($builder_derive),+)])?
+ $visibility struct $builder_name
+ {
+ $(
+ $field: $field_type,
+ )*
+ }
+
+ impl $builder_name
+ {
+ $(
+ $visibility fn $field(mut self, $field: $field_type) -> Self
+ {
+ self.$field = $field;
+ self
+ }
+ )*
+
+ $visibility fn build(self) -> $name {
+ $name {
+ $(
+ $field: self.$field,
+ )*
+ }
+ }
+ }
+ };
+}
+
+pub(crate) use builder;