diff --git a/compiler-base/src/env/env_native.rs b/compiler-base/src/env/env_native.rs index 17e9b57..8579afa 100644 --- a/compiler-base/src/env/env_native.rs +++ b/compiler-base/src/env/env_native.rs @@ -51,8 +51,10 @@ impl From> for RefCounted<[T]> { } } -impl From> for RefCounted - where T: ?Sized { +impl From> for RefCounted +where + T: ?Sized, +{ #[inline] fn from(v: Box) -> Self { Self { diff --git a/compiler-base/src/env/env_wasm.rs b/compiler-base/src/env/env_wasm.rs index a269832..9c1ed02 100644 --- a/compiler-base/src/env/env_wasm.rs +++ b/compiler-base/src/env/env_wasm.rs @@ -48,13 +48,12 @@ impl From> for RefCounted<[T]> { } impl From> for RefCounted - where T: ?Sized +where + T: ?Sized, { #[inline] fn from(v: Box) -> Self { - Self { - inner: Rc::from(v), - } + Self { inner: Rc::from(v) } } } diff --git a/compiler-base/src/env/mod.rs b/compiler-base/src/env/mod.rs index 665e941..72d251a 100644 --- a/compiler-base/src/env/mod.rs +++ b/compiler-base/src/env/mod.rs @@ -4,8 +4,8 @@ use std::cell::RefCell; use std::fmt::Display; use std::ops::Deref; -use crate::res::Loader; use crate::macros::late_global; +use crate::res::Loader; #[cfg(feature = "wasm")] pub mod env_wasm; @@ -41,7 +41,7 @@ pub mod site { None => match origin.strip_prefix("http://") { Some(domain) => RefCounted::from(domain), None => origin, - } + }, } } } diff --git a/compiler-base/src/util/data_url.rs b/compiler-base/src/util/data_url.rs index 00dd82e..cf21040 100644 --- a/compiler-base/src/util/data_url.rs +++ b/compiler-base/src/util/data_url.rs @@ -20,7 +20,6 @@ pub enum DataUrlParseError { NoData, #[error("Error decoding base64 from data url: {0}")] InvalidBase64(#[from] base64::DecodeError), - } /// Decode data url to bytes. Supports base64 and URL encoding. diff --git a/compiler-core/src/comp/iterator.rs b/compiler-core/src/comp/iterator.rs index fab905a..3e0d822 100644 --- a/compiler-core/src/comp/iterator.rs +++ b/compiler-core/src/comp/iterator.rs @@ -12,7 +12,9 @@ impl<'p> CompDoc<'p> { /// Iterate over each CompLine of the CompDoc pub fn lines_mut(&mut self) -> impl Iterator { - self.route.iter_mut().flat_map(|section| section.lines.iter_mut()) + self.route + .iter_mut() + .flat_map(|section| section.lines.iter_mut()) } /// Iterate over each DocRichText of the CompDoc. @@ -72,10 +74,10 @@ pub struct LineRichTextIterMut<'c> { impl<'c, 'p> RichTextIter<'c, 'p> { pub fn new(doc: &'c CompDoc<'p>) -> Self { - Self { - doc, + Self { + doc, with_preface: false, - with_counter: false + with_counter: false, } } pub fn with_preface(mut self) -> Self { @@ -89,8 +91,8 @@ impl<'c, 'p> RichTextIter<'c, 'p> { } impl<'c, 'p> RichTextIterMut<'c, 'p> { pub fn new(doc: &'c mut CompDoc<'p>) -> Self { - Self { - doc, + Self { + doc, with_preface: false, with_counter: false, } @@ -106,9 +108,9 @@ impl<'c, 'p> RichTextIterMut<'c, 'p> { } impl<'c> LineRichTextIter<'c> { pub fn new(line: &'c CompLine) -> Self { - Self { - line, - with_counter: false + Self { + line, + with_counter: false, } } pub fn with_counter(mut self) -> Self { @@ -118,9 +120,9 @@ impl<'c> LineRichTextIter<'c> { } impl<'c> LineRichTextIterMut<'c> { pub fn new(line: &'c mut CompLine) -> Self { - Self { - line, - with_counter: false + Self { + line, + with_counter: false, } } pub fn with_counter(mut self) -> Self { @@ -129,15 +131,15 @@ impl<'c> LineRichTextIterMut<'c> { } } -impl<'c, 'p> IntoIterator for RichTextIter<'c, 'p> -{ +impl<'c, 'p> IntoIterator for RichTextIter<'c, 'p> { type Item = &'c DocRichTextBlock; type IntoIter = DynIter<'c, Self::Item>; fn into_iter(self) -> Self::IntoIter { let iter = self.doc.route.iter().flat_map(move |section| { - section.lines.iter().flat_map(move |line| { - rich_text_iter(line, self.with_counter) - }) + section + .lines + .iter() + .flat_map(move |line| rich_text_iter(line, self.with_counter)) }); if self.with_preface { let preface_iter = self.doc.preface.iter().flat_map(|text| text.iter()); @@ -146,15 +148,15 @@ impl<'c, 'p> IntoIterator for RichTextIter<'c, 'p> DynIter::new(iter) } } -impl<'c, 'p> IntoIterator for RichTextIterMut<'c, 'p> -{ +impl<'c, 'p> IntoIterator for RichTextIterMut<'c, 'p> { type Item = &'c mut DocRichTextBlock; type IntoIter = DynIter<'c, Self::Item>; fn into_iter(self) -> Self::IntoIter { let iter = self.doc.route.iter_mut().flat_map(move |section| { - section.lines.iter_mut().flat_map(move |line| { - rich_text_iter_mut(line, self.with_counter) - }) + section + .lines + .iter_mut() + .flat_map(move |line| rich_text_iter_mut(line, self.with_counter)) }); if self.with_preface { let preface_iter = self.doc.preface.iter_mut().flat_map(|text| text.iter_mut()); @@ -163,8 +165,7 @@ impl<'c, 'p> IntoIterator for RichTextIterMut<'c, 'p> DynIter::new(iter) } } -impl<'c> IntoIterator for LineRichTextIter<'c> -{ +impl<'c> IntoIterator for LineRichTextIter<'c> { type Item = &'c DocRichTextBlock; type IntoIter = DynIter<'c, Self::Item>; fn into_iter(self) -> Self::IntoIter { @@ -172,8 +173,7 @@ impl<'c> IntoIterator for LineRichTextIter<'c> DynIter::new(iter) } } -impl<'c> IntoIterator for LineRichTextIterMut<'c> -{ +impl<'c> IntoIterator for LineRichTextIterMut<'c> { type Item = &'c mut DocRichTextBlock; type IntoIter = DynIter<'c, Self::Item>; fn into_iter(self) -> Self::IntoIter { @@ -182,14 +182,14 @@ impl<'c> IntoIterator for LineRichTextIterMut<'c> } } -fn rich_text_iter<'c>(line: &'c CompLine, with_counter: bool) -> impl Iterator { - let iter = line.text.iter() +fn rich_text_iter(line: &CompLine, with_counter: bool) -> impl Iterator { + let iter = line + .text + .iter() .chain(line.secondary_text.iter()) - .chain(line.notes.iter().flat_map(|note| { - match note { - DocNote::Text { content } => DynIter::new(content.iter()), - _ => DynIter::new(std::iter::empty()) - } + .chain(line.notes.iter().flat_map(|note| match note { + DocNote::Text { content } => DynIter::new(content.iter()), + _ => DynIter::new(std::iter::empty()), })) .chain({ if !with_counter { @@ -211,14 +211,17 @@ fn rich_text_iter<'c>(line: &'c CompLine, with_counter: bool) -> impl Iterator(line: &'c mut CompLine, with_counter: bool) -> impl Iterator { - let iter = line.text.iter_mut() +fn rich_text_iter_mut( + line: &mut CompLine, + with_counter: bool, +) -> impl Iterator { + let iter = line + .text + .iter_mut() .chain(line.secondary_text.iter_mut()) - .chain(line.notes.iter_mut().flat_map(|note| { - match note { - DocNote::Text { content } => DynIter::new(content.iter_mut()), - _ => DynIter::new(std::iter::empty()) - } + .chain(line.notes.iter_mut().flat_map(|note| match note { + DocNote::Text { content } => DynIter::new(content.iter_mut()), + _ => DynIter::new(std::iter::empty()), })) .chain({ if !with_counter { @@ -240,11 +243,15 @@ fn rich_text_iter_mut<'c>(line: &'c mut CompLine, with_counter: bool) -> impl It iter } -pub struct DynIter<'c, T>(Box + 'c + Send + Sync>) where T: 'c; +pub struct DynIter<'c, T>(Box + 'c + Send + Sync>) +where + T: 'c; impl<'c, T> DynIter<'c, T> { fn new(iter: I) -> Self - where I: Iterator + 'c + Send + Sync { + where + I: Iterator + 'c + Send + Sync, + { Self(Box::new(iter)) } } diff --git a/compiler-core/src/expo/mod.rs b/compiler-core/src/expo/mod.rs index 90b55a3..cff4d82 100644 --- a/compiler-core/src/expo/mod.rs +++ b/compiler-core/src/expo/mod.rs @@ -137,7 +137,10 @@ impl<'p> CompDoc<'p> { for plugin in &mut plugins { if req.plugin_id == plugin.get_id() { - let result = match plugin.on_export_comp_doc(&req.export_id, &req.payload, self).await { + let result = match plugin + .on_export_comp_doc(&req.export_id, &req.payload, self) + .await + { Ok(None) => None, Ok(Some(expo_doc)) => Some(expo_doc), Err(e) => Some(ExpoDoc::Error(e.to_string())), @@ -162,11 +165,13 @@ impl<'p> ExecContext<'p> { for plugin in &mut plugins { if req.plugin_id == plugin.get_id() { - let result = - match plugin.on_export_exec_doc(&req.export_id, req.payload, &self.exec_doc).await { - Ok(expo_doc) => expo_doc, - Err(e) => ExpoDoc::Error(e.to_string()), - }; + let result = match plugin + .on_export_exec_doc(&req.export_id, req.payload, &self.exec_doc) + .await + { + Ok(expo_doc) => expo_doc, + Err(e) => ExpoDoc::Error(e.to_string()), + }; return result; } } diff --git a/compiler-core/src/plugin/builtin/botw_unstable.rs b/compiler-core/src/plugin/builtin/botw_unstable.rs index bf116d3..9dac36a 100644 --- a/compiler-core/src/plugin/builtin/botw_unstable.rs +++ b/compiler-core/src/plugin/builtin/botw_unstable.rs @@ -5,11 +5,11 @@ use std::borrow::Cow; use serde_json::Value; use crate::comp::{CompDoc, CompLine, CompMovement}; +use crate::env::yield_budget; use crate::json::Coerce; use crate::lang::{DocDiagnostic, DocRichText, DocRichTextBlock}; -use crate::plugin::{PluginResult, PluginRuntime}; -use crate::env::yield_budget; use crate::macros::async_trait; +use crate::plugin::{PluginResult, PluginRuntime}; const FURY: &str = "fury"; const GALE: &str = "gale"; diff --git a/compiler-core/src/plugin/builtin/export_livesplit.rs b/compiler-core/src/plugin/builtin/export_livesplit.rs index dd1f0f9..5e6d79d 100644 --- a/compiler-core/src/plugin/builtin/export_livesplit.rs +++ b/compiler-core/src/plugin/builtin/export_livesplit.rs @@ -7,12 +7,12 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use crate::comp::{CompDoc, CompLine, CompSection}; +use crate::env::{self, yield_budget, RefCounted}; use crate::expo::{ExpoBlob, ExpoDoc, ExportIcon, ExportMetadata}; +use crate::export_error; use crate::json::Coerce; -use crate::plugin::{PluginResult, PluginRuntime}; use crate::macros::async_trait; -use crate::export_error; -use crate::env::{self, RefCounted, yield_budget}; +use crate::plugin::{PluginResult, PluginRuntime}; use crate::res::ResPath; pub struct ExportLiveSplitPlugin; @@ -86,7 +86,7 @@ impl PluginRuntime for ExportLiveSplitPlugin { // build lines to split let mut split_sections = Vec::with_capacity(doc.route.len()); for section in &doc.route { - let mut split_lines= vec![]; + let mut split_lines = vec![]; for line in §ion.lines { yield_budget(64).await; if should_split_on(line, &split_types) { @@ -162,7 +162,7 @@ fn should_split_on(line: &CompLine, split_types: &BTreeSet) -> bool { } async fn build_icon_cache( - doc: &CompDoc<'_>, + doc: &CompDoc<'_>, split_sections: &[(&CompSection, Vec<&CompLine>)], webp_compat: WebpCompat, ) -> Result>, String> { @@ -179,7 +179,11 @@ async fn build_icon_cache( continue; } if let Some(icon_url) = doc.config.icons.get(icon_id) { - icon_futures.push(load_icon(icon_id.to_string(), icon_url.to_string(), webp_compat)) + icon_futures.push(load_icon( + icon_id.to_string(), + icon_url.to_string(), + webp_compat, + )) } } } @@ -189,18 +193,16 @@ async fn build_icon_cache( match result { Ok(Ok((id, bytes))) => { cache.insert(id, bytes.to_vec()); - }, - Ok(Err(e)) | Err(e) => { - return Err(e) - }, + } + Ok(Err(e)) | Err(e) => return Err(e), } } Ok(cache) } fn create_segment( - line: &CompLine, - name: &str, + line: &CompLine, + name: &str, include_icon: bool, icon_cache: &BTreeMap>, ) -> livesplit_core::Segment { @@ -223,12 +225,20 @@ enum WebpCompat { /// Emit error. This is the default Error, /// Skip the icon - Skip + Skip, } -async fn load_icon(icon_id: String, icon_url: String, webp_compat: WebpCompat) -> Result<(String, RefCounted<[u8]>), String> { +async fn load_icon( + icon_id: String, + icon_url: String, + webp_compat: WebpCompat, +) -> Result<(String, RefCounted<[u8]>), String> { let loader = match env::global_loader::get() { - None => return Err("No global loader available to load the icons for split export!".to_string()), + None => { + return Err( + "No global loader available to load the icons for split export!".to_string(), + ) + } Some(loader) => loader, }; @@ -240,7 +250,7 @@ async fn load_icon(icon_id: String, icon_url: String, webp_compat: WebpCompat) - if data.starts_with(b"RIFF") { if let WebpCompat::Error = webp_compat { - return Err(format!("Failed to load icon `{icon_url}`: RIFF (webp) icons are not supported by LiveSplit. Set the option `webp-compat: skip` to skip invalid webp icons.")) + return Err(format!("Failed to load icon `{icon_url}`: RIFF (webp) icons are not supported by LiveSplit. Set the option `webp-compat: skip` to skip invalid webp icons.")); } } diff --git a/compiler-core/src/plugin/builtin/link.rs b/compiler-core/src/plugin/builtin/link.rs index 89e1e76..122ec6c 100644 --- a/compiler-core/src/plugin/builtin/link.rs +++ b/compiler-core/src/plugin/builtin/link.rs @@ -4,13 +4,13 @@ use std::borrow::Cow; -use crate::env::yield_budget; use crate::comp::CompDoc; +use crate::env::yield_budget; use crate::lang::DocRichTextBlock; +use crate::macros::async_trait; use crate::pack::CompileContext; use crate::prep::{DocTag, DocTagColor}; use crate::prop; -use crate::macros::async_trait; use crate::plugin::{PluginResult, PluginRuntime}; diff --git a/compiler-core/src/plugin/builtin/metrics.rs b/compiler-core/src/plugin/builtin/metrics.rs index 1ffeacc..00477d3 100644 --- a/compiler-core/src/plugin/builtin/metrics.rs +++ b/compiler-core/src/plugin/builtin/metrics.rs @@ -6,8 +6,8 @@ use serde_json::Value; use crate::comp::CompDoc; use crate::exec::ExecDoc; use crate::json::Coerce; -use crate::prop; use crate::macros::async_trait; +use crate::prop; use crate::plugin::{PluginResult, PluginRuntime}; diff --git a/compiler-core/src/plugin/builtin/split_format.rs b/compiler-core/src/plugin/builtin/split_format.rs index a05cc0f..e9c7bad 100644 --- a/compiler-core/src/plugin/builtin/split_format.rs +++ b/compiler-core/src/plugin/builtin/split_format.rs @@ -8,11 +8,11 @@ use std::collections::BTreeMap; use serde_json::Value; use crate::comp::{CompDoc, CompLine}; +use crate::env::yield_budget; use crate::json::Coerce; use crate::lang::{self, DocRichText}; -use crate::plugin::{PluginResult, PluginRuntime}; use crate::macros::async_trait; -use crate::env::yield_budget; +use crate::plugin::{PluginResult, PluginRuntime}; pub struct SplitFormatPlugin { formats: BTreeMap, diff --git a/compiler-core/src/plugin/builtin/variables/mod.rs b/compiler-core/src/plugin/builtin/variables/mod.rs index 042a05d..0b722fb 100644 --- a/compiler-core/src/plugin/builtin/variables/mod.rs +++ b/compiler-core/src/plugin/builtin/variables/mod.rs @@ -6,14 +6,14 @@ use std::collections::HashMap; use serde_json::{json, Map, Value}; use crate::comp::CompDoc; +use crate::env::yield_budget; use crate::json::Coerce; use crate::lang::{self, DocDiagnostic, DocRichTextBlock}; +use crate::macros::async_trait; use crate::pack::CompileContext; use crate::plugin::{PluginResult, PluginRuntime}; use crate::prep::{DocTag, DocTagColor}; use crate::prop; -use crate::macros::async_trait; -use crate::env::yield_budget; mod convert; mod transform; @@ -320,7 +320,8 @@ impl PluginRuntime for VariablesPlugin { } std::mem::swap(&mut line.diagnostics, &mut diagnostics); if self.expose { - line.properties.insert(prop::VALS.to_string(), self.get_vals()); + line.properties + .insert(prop::VALS.to_string(), self.get_vals()); } self.clear_temporary(); } diff --git a/compiler-core/src/plugin/mod.rs b/compiler-core/src/plugin/mod.rs index 04de613..91dc84d 100644 --- a/compiler-core/src/plugin/mod.rs +++ b/compiler-core/src/plugin/mod.rs @@ -5,7 +5,7 @@ use serde_json::Value; use crate::comp::CompDoc; use crate::exec::ExecDoc; use crate::expo::{ExpoDoc, ExportMetadata}; -use crate::macros::{derive_wasm, async_trait}; +use crate::macros::{async_trait, derive_wasm}; use crate::pack::CompileContext; mod error; diff --git a/compiler-macros/src/late_global_impl.rs b/compiler-macros/src/late_global_impl.rs index 447a369..1e92f64 100644 --- a/compiler-macros/src/late_global_impl.rs +++ b/compiler-macros/src/late_global_impl.rs @@ -1,6 +1,5 @@ //! Implementation for expanding `late_global` - use proc_macro::TokenStream; use syn::ItemMod; @@ -15,20 +14,25 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> TokenStream { let vis = &parsed_mod.vis; let name = &parsed_mod.ident; - let attrs = parsed_mod.attrs.into_iter().map(|attr| { - quote::quote! { - #attr - } - }).collect::(); + let attrs = parsed_mod + .attrs + .into_iter() + .map(|attr| { + quote::quote! { + #attr + } + }) + .collect::(); let content = match parsed_mod.content { - Some((_, content)) => { - content.into_iter().map(|item| { + Some((_, content)) => content + .into_iter() + .map(|item| { quote::quote! { #item } - }).collect::() - } + }) + .collect::(), None => quote::quote!(), }; @@ -44,7 +48,7 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> TokenStream { static GLOBAL: std::sync::OnceLock> = std::sync::OnceLock::new(); #[cfg(not(feature = "wasm"))] /// Get the late global value - pub fn get() -> Option> { + pub fn get() -> Option> { GLOBAL.get().map(RefCounted::clone) } #[cfg(not(feature = "wasm"))] @@ -57,12 +61,12 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> TokenStream { } #[cfg(feature = "wasm")] /// Get the late global value (cloned) - pub fn get() -> Option> { + pub fn get() -> Option> { GLOBAL.with(|cell| cell.get().map(RefCounted::clone)) } #[cfg(feature = "wasm")] /// Set the late global value - pub fn set(val: RefCounted<#typ>) -> Result<(), RefCounted<#typ>> { + pub fn set(val: RefCounted<#typ>) -> Result<(), RefCounted<#typ>> { GLOBAL.with(|cell| cell.set(val)) } #content diff --git a/compiler-wasm/src/lib.rs b/compiler-wasm/src/lib.rs index f383392..2ba92d5 100644 --- a/compiler-wasm/src/lib.rs +++ b/compiler-wasm/src/lib.rs @@ -33,7 +33,6 @@ pub fn init( let loader: Box = Box::new(LoaderInWasm); let _ = celerc::env::global_loader::set(RefCounted::from(loader)); - info!("compiler initialized"); } diff --git a/compiler-wasm/src/loader.rs b/compiler-wasm/src/loader.rs index 8988516..4ae820f 100644 --- a/compiler-wasm/src/loader.rs +++ b/compiler-wasm/src/loader.rs @@ -76,7 +76,6 @@ pub async fn load_url(url: &str) -> ResResult> { return Ok(data); } - // this is essentially try { Ok(await load_url(url)) } catch (e) { Err(e) } let result = async { LOAD_URL diff --git a/server/src/boot.rs b/server/src/boot.rs index 1a899b5..daa13a5 100644 --- a/server/src/boot.rs +++ b/server/src/boot.rs @@ -48,7 +48,7 @@ async fn process_site_origin_for_path( result?; } return Ok(()); - } + } if path .extension() diff --git a/server/src/compiler/loader.rs b/server/src/compiler/loader.rs index 2ebd46b..34f4c51 100644 --- a/server/src/compiler/loader.rs +++ b/server/src/compiler/loader.rs @@ -18,7 +18,7 @@ static LOADER: Lazy> = pub fn setup_global_loader() { info!("setting up global loader..."); - let loader: Box = Box::new(ServerResourceLoader::default()); + let loader: Box = Box::::default(); if celerc::env::global_loader::set(RefCounted::from(loader)).is_err() { error!("failed to set global loader because it is already set!"); } @@ -46,7 +46,7 @@ impl ServerResourceLoader { let cache = Mutex::new(TimedSizedCache::with_size_and_lifespan(128, 301)); Self { http_client, cache } } - /// Load a resource from Url or cache. + /// Load a resource from Url or cache. /// /// On error, returns an additional should_retry flag. async fn load_url(&self, url: &str) -> Result, (ResError, bool)> { @@ -59,10 +59,13 @@ impl ServerResourceLoader { let data = match celerc::util::bytes_from_data_url(url) { Ok(data) => data.into_owned(), Err(e) => { - return Err((ResError::FailToLoadUrl( - url.to_string(), - format!("Failed to parse data URL: {e}"), - ), false)); + return Err(( + ResError::FailToLoadUrl( + url.to_string(), + format!("Failed to parse data URL: {e}"), + ), + false, + )); } }; let data = RefCounted::from(data); @@ -70,7 +73,6 @@ impl ServerResourceLoader { return Ok(data); } - let response = self .http_client .get(url)