From d33e57d4b71c8ba559e9093b6ac8bac65542ee93 Mon Sep 17 00:00:00 2001 From: Chris <89366859+chrisp60@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:26:10 -0500 Subject: [PATCH] feat: `Default` for `LeptosOptions`, `ConfFile` (#2208) Co-authored-by: chrisp60 --- leptos_config/src/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/leptos_config/src/lib.rs b/leptos_config/src/lib.rs index e1f5f3567..ffde76e1a 100644 --- a/leptos_config/src/lib.rs +++ b/leptos_config/src/lib.rs @@ -13,7 +13,7 @@ use typed_builder::TypedBuilder; /// A Struct to allow us to parse LeptosOptions from the file. Not really needed, most interactions should /// occur with LeptosOptions -#[derive(Clone, Debug, serde::Deserialize)] +#[derive(Clone, Debug, serde::Deserialize, Default)] #[serde(rename_all = "kebab-case")] pub struct ConfFile { pub leptos_options: LeptosOptions, @@ -27,7 +27,7 @@ pub struct ConfFile { #[serde(rename_all = "kebab-case")] pub struct LeptosOptions { /// The name of the WASM and JS files generated by wasm-bindgen. Defaults to the crate name with underscores instead of dashes - #[builder(setter(into))] + #[builder(setter(into), default=default_output_name())] pub output_name: String, /// The path of the all the files generated by cargo-leptos. This defaults to '.' for convenience when integrating with other /// tools. @@ -112,6 +112,16 @@ impl LeptosOptions { } } +impl Default for LeptosOptions { + fn default() -> Self { + LeptosOptions::builder().build() + } +} + +fn default_output_name() -> String { + env!("CARGO_CRATE_NAME").replace('-', "_") +} + fn default_site_root() -> String { ".".to_string() }