summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/types/project.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/types/project.rs b/src/types/project.rs
index 13f84eb..ceb4f84 100644
--- a/src/types/project.rs
+++ b/src/types/project.rs
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
extern crate fxhash;
use iced::Theme;
-use rust_format::{Edition, Formatter, RustFmt};
+use rust_format::{Formatter, PostProcess, PrettyPlease};
use serde::{Deserialize, Serialize};
use super::rendered_element::RenderedElement;
@@ -103,25 +103,37 @@ impl Project {
r#"// Automatically generated by iced Builder
use iced::{{widget::{{{imports}}},Element}};
+_blank_!();
+
fn main() -> iced::Result {{
iced::application(State::default, State::update, State::view).title("{title}").theme(State::theme).run()
}}
+_blank_!();
+
#[derive(Default)]
struct State;
+_blank_!();
+
#[derive(Debug, Clone)]
enum Message {{}}
+_blank_!();
+
impl State {{
fn update(&mut self, _message: Message) {{
// Insert your desired update logic here
}}
+ _blank_!();
+
fn theme(&self) -> iced::Theme {{
iced::Theme::{theme}
}}
+ _blank_!();
+
fn view(&self) -> Element<Message> {{
{view}.into()
}}
@@ -134,19 +146,9 @@ impl State {{
);
let config = rust_format::Config::new_str()
- .edition(Edition::Rust2021)
- .option("trailing_comma", "Never")
- .option("imports_granularity", "Crate");
- let rustfmt = RustFmt::from_config(config);
-
- 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(_)) => {
- return Ok(app_code);
- }
- Err(err) => return Err(err.into()),
- }
+ .post_proc(PostProcess::ReplaceMarkers);
+
+ Ok(PrettyPlease::from_config(config).format_str(&app_code)?)
}
None => Err("No element tree present".into()),
};