diff options
| author | pml68 <contact@pml68.dev> | 2025-06-27 12:12:22 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-06-27 12:12:22 +0200 |
| commit | 2bbe61b1300ee6fcc13e114091a7aaaa0d13e56b (patch) | |
| tree | 6f697ab38496201ed0206f0c7f1a17e201ef5410 | |
| parent | ci: rename `all` jobs -> `lint` & `test` [skip ci] (diff) | |
| download | iced-builder-2bbe61b1300ee6fcc13e114091a7aaaa0d13e56b.tar.gz | |
feat: make `rustfmt` optional as a dependency
Diffstat (limited to '')
| -rw-r--r-- | PKGBUILD | 4 | ||||
| -rw-r--r-- | src/types/project.rs | 26 | ||||
| -rwxr-xr-x | src/types/rendered_element.rs | 2 |
3 files changed, 23 insertions, 9 deletions
@@ -11,11 +11,11 @@ depends=( gcc-libs glibc openssl - rustfmt ) +optdepends=('rustfmt: better code formatting') makedepends=( git - cargo + 'cargo>=1.85.0' clang mold ) diff --git a/src/types/project.rs b/src/types/project.rs index 7262ccf..9f78445 100644 --- a/src/types/project.rs +++ b/src/types/project.rs @@ -1,3 +1,4 @@ +use std::io; use std::path::{Path, PathBuf}; extern crate fxhash; @@ -103,7 +104,7 @@ impl Project { use iced::{{widget::{{{imports}}},Element}}; fn main() -> iced::Result {{ - iced::application(State::default, State::update, State::view).title("{}").theme(State::theme).run() + iced::application(State::default, State::update, State::view).title("{title}").theme(State::theme).run() }} #[derive(Default)] @@ -113,28 +114,41 @@ struct State; enum Message {{}} impl State {{ - fn update(&mut self, _message: Message) {{}} + fn update(&mut self, _message: Message) {{ + // Insert your desired update logic here + }} fn theme(&self) -> iced::Theme {{ - iced::Theme::{} + iced::Theme::{theme} }} fn view(&self) -> Element<Message> {{ {view}.into() }} }}"#, - match self.title { + title = match self.title { Some(ref t) => t, None => "New app", }, - theme.to_string().replace(" ", "") + theme = theme.to_string().replace(" ", "") ); + let config = rust_format::Config::new_str() .edition(Edition::Rust2021) .option("trailing_comma", "Never") .option("imports_granularity", "Crate"); let rustfmt = RustFmt::from_config(config); - Ok(rustfmt.format_str(app_code)?) + + match rustfmt.format_str(&app_code) { + Ok(code) => return Ok(code), + // rustfmt is missing, that's fine, we fall back to manual formatting + Err(rust_format::Error::IOError(err)) + if err.kind() == io::ErrorKind::NotFound => + { + return Ok(app_code); + } + Err(err) => return Err(err.into()), + } } None => Err("No element tree present".into()), }; diff --git a/src/types/rendered_element.rs b/src/types/rendered_element.rs index a6618b3..b7fd839 100755 --- a/src/types/rendered_element.rs +++ b/src/types/rendered_element.rs @@ -178,7 +178,7 @@ impl RenderedElement { let mut view = String::new(); let mut options = String::new(); - for (k, v) in self.options.clone() { + for (k, v) in &self.options { if let Some(v) = v { options = format!("{options}.{k}({v})"); } |
