diff --git a/src/config.rs b/src/config.rs index e9e11f1..603ba85 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,12 +27,13 @@ use glutin::dpi::LogicalSize; /// /// let config = ConfigBuilder::default() /// .invert_y(false) -/// .build().unwrap(); +/// .build(); /// ``` /// /// If there's a config option you want to see or think is missing, please open an issue! #[non_exhaustive] #[builder(default)] +#[builder(build_fn(skip))] #[derive(Clone, PartialEq, Debug, Builder)] pub struct Config { /// Sets the pixel dimensions of the buffer. The buffer will automatically stretch to fill the @@ -54,6 +55,28 @@ pub struct Config { pub invert_y: bool } +impl ConfigBuilder { + /// Builds a new [`Config`]. + pub fn build(&self) -> Config { + let mut config = Config::default(); + + macro_rules! fields { + ($($n:ident),+) => { + $( + if let Some($n) = &self.$n { + config.$n = $n.clone(); + } + )+ + } + } + + // I guess this is better than implementing the entire builder by hand + fields!(buffer_size, resizable, window_title, window_size, invert_y); + + config + } +} + impl Default for Config { fn default() -> Self { Config {