From 2c6b7a81342d59c7666eb228783d4a97f3ccd4b0 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 31 Oct 2025 10:39:16 +0800 Subject: [PATCH 1/2] chore: fix new clippy warnings (derive default) --- crates/tauri-bundler/src/error.rs | 13 ++++--- crates/tauri-cli/src/interface/rust.rs | 9 ++--- crates/tauri-runtime/src/lib.rs | 9 ++--- crates/tauri-utils/src/config.rs | 36 +++++--------------- crates/tauri-utils/src/config_v1/mod.rs | 45 ++++++------------------- crates/tauri-utils/src/html.rs | 9 ++--- crates/tauri-utils/src/lib.rs | 9 ++--- crates/tauri/src/pattern.rs | 9 ++--- crates/tauri/src/tray/mod.rs | 18 +++------- 9 files changed, 40 insertions(+), 117 deletions(-) diff --git a/crates/tauri-bundler/src/error.rs b/crates/tauri-bundler/src/error.rs index 92adf63a7ffc..518cb6ca9b71 100644 --- a/crates/tauri-bundler/src/error.rs +++ b/crates/tauri-bundler/src/error.rs @@ -99,11 +99,14 @@ pub enum Error { #[error("Wrong package type {0} for platform {1}")] InvalidPackageType(String, String), /// Bundle type symbol missing in binary - #[cfg(target_os = "linux")] - #[error("__TAURI_BUNDLE_TYPE variable not found in binary. Make sure tauri crate and tauri-cli are up to date and that symbol stripping is disabled (https://doc.rust-lang.org/cargo/reference/profiles.html#strip)")] - MissingBundleTypeVar, - #[cfg(not(target_os = "linux"))] - #[error("__TAURI_BUNDLE_TYPE variable not found in binary. Make sure tauri crate and tauri-cli are up to date")] + #[cfg_attr( + target_os = "linux", + error("__TAURI_BUNDLE_TYPE variable not found in binary. Make sure tauri crate and tauri-cli are up to date and that symbol stripping is disabled (https://doc.rust-lang.org/cargo/reference/profiles.html#strip)") + )] + #[cfg_attr( + not(target_os = "linux"), + error("__TAURI_BUNDLE_TYPE variable not found in binary. Make sure tauri crate and tauri-cli are up to date") + )] MissingBundleTypeVar, /// Failed to write binary file changed #[error("Failed to write binary file changes: `{0}`")] diff --git a/crates/tauri-cli/src/interface/rust.rs b/crates/tauri-cli/src/interface/rust.rs index 067dd5ca3f79..fd49ac35bb57 100644 --- a/crates/tauri-cli/src/interface/rust.rs +++ b/crates/tauri-cli/src/interface/rust.rs @@ -785,7 +785,7 @@ pub struct UpdaterConfig { } /// Install modes for the Windows update. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Default, Debug, PartialEq, Eq, Clone)] pub enum WindowsUpdateInstallMode { /// Specifies there's a basic UI during the installation process, including a final dialog box at the end. BasicUi, @@ -793,17 +793,12 @@ pub enum WindowsUpdateInstallMode { /// Requires admin privileges if the installer does. Quiet, /// Specifies unattended mode, which means the installation only shows a progress bar. + #[default] Passive, // to add more modes, we need to check if the updater relaunch makes sense // i.e. for a full UI mode, the user can also mark the installer to start the app } -impl Default for WindowsUpdateInstallMode { - fn default() -> Self { - Self::Passive - } -} - impl<'de> Deserialize<'de> for WindowsUpdateInstallMode { fn deserialize(deserializer: D) -> std::result::Result where diff --git a/crates/tauri-runtime/src/lib.rs b/crates/tauri-runtime/src/lib.rs index a8d17181eb53..2874d16b9a42 100644 --- a/crates/tauri-runtime/src/lib.rs +++ b/crates/tauri-runtime/src/lib.rs @@ -90,23 +90,18 @@ pub enum UserAttentionType { Informational, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] +#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Deserialize)] #[serde(tag = "type")] pub enum DeviceEventFilter { /// Always filter out device events. Always, /// Filter out device events while the window is not focused. + #[default] Unfocused, /// Report all device events regardless of window focus. Never, } -impl Default for DeviceEventFilter { - fn default() -> Self { - Self::Unfocused - } -} - /// Defines the orientation that a window resize will be performed. #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] pub enum ResizeDirection { diff --git a/crates/tauri-utils/src/config.rs b/crates/tauri-utils/src/config.rs index 40d33292a17e..37c77abff8ac 100644 --- a/crates/tauri-utils/src/config.rs +++ b/crates/tauri-utils/src/config.rs @@ -208,9 +208,10 @@ impl<'de> Deserialize<'de> for BundleType { } /// Targets to bundle. Each value is case insensitive. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Default)] pub enum BundleTarget { /// Bundle all targets. + #[default] All, /// A list of bundle targets. List(Vec), @@ -257,12 +258,6 @@ impl schemars::JsonSchema for BundleTarget { } } -impl Default for BundleTarget { - fn default() -> Self { - Self::All - } -} - impl Serialize for BundleTarget { fn serialize(&self, serializer: S) -> std::result::Result where @@ -805,7 +800,7 @@ pub struct WixConfig { /// Compression algorithms used in the NSIS installer. /// /// See -#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Default)] #[cfg_attr(feature = "schema", derive(JsonSchema))] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub enum NsisCompression { @@ -814,19 +809,14 @@ pub enum NsisCompression { /// BZIP2 usually gives better compression ratios than ZLIB, but it is a bit slower and uses more memory. With the default compression level it uses about 4 MB of memory. Bzip2, /// LZMA (default) is a new compression method that gives very good compression ratios. The decompression speed is high (10-20 MB/s on a 2 GHz CPU), the compression speed is lower. The memory size that will be used for decompression is the dictionary size plus a few KBs, the default is 8 MB. + #[default] Lzma, /// Disable compression None, } -impl Default for NsisCompression { - fn default() -> Self { - Self::Lzma - } -} - /// Install Modes for the NSIS installer. -#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] +#[derive(Default, Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "schema", derive(JsonSchema))] pub enum NSISInstallerMode { @@ -835,6 +825,7 @@ pub enum NSISInstallerMode { /// Install the app by default in a directory that doesn't require Administrator access. /// /// Installer metadata will be saved under the `HKCU` registry path. + #[default] CurrentUser, /// Install the app by default in the `Program Files` folder directory requires Administrator /// access for the installation. @@ -849,12 +840,6 @@ pub enum NSISInstallerMode { Both, } -impl Default for NSISInstallerMode { - fn default() -> Self { - Self::CurrentUser - } -} - /// Configuration for the Installer bundle using NSIS. #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)] #[cfg_attr(feature = "schema", derive(JsonSchema))] @@ -2685,11 +2670,12 @@ impl<'de> Deserialize<'de> for CapabilityEntry { /// The application pattern. #[skip_serializing_none] -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default)] #[serde(rename_all = "lowercase", tag = "use", content = "options")] #[cfg_attr(feature = "schema", derive(JsonSchema))] pub enum PatternKind { /// Brownfield pattern. + #[default] Brownfield, /// Isolation pattern. Recommended for security purposes. Isolation { @@ -2698,12 +2684,6 @@ pub enum PatternKind { }, } -impl Default for PatternKind { - fn default() -> Self { - Self::Brownfield - } -} - /// The App configuration object. /// /// See more: diff --git a/crates/tauri-utils/src/config_v1/mod.rs b/crates/tauri-utils/src/config_v1/mod.rs index 5fc9450d963f..a8a5fc2e51d7 100644 --- a/crates/tauri-utils/src/config_v1/mod.rs +++ b/crates/tauri-utils/src/config_v1/mod.rs @@ -131,9 +131,10 @@ impl<'de> Deserialize<'de> for BundleType { } /// Targets to bundle. Each value is case insensitive. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Default)] pub enum BundleTarget { /// Bundle all targets. + #[default] All, /// A list of bundle targets. List(Vec), @@ -251,12 +252,6 @@ impl schemars::JsonSchema for BundleTarget { } } -impl Default for BundleTarget { - fn default() -> Self { - Self::All - } -} - impl Serialize for BundleTarget { fn serialize(&self, serializer: S) -> std::result::Result where @@ -552,7 +547,7 @@ pub struct NsisConfig { } /// Install Modes for the NSIS installer. -#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum NSISInstallerMode { @@ -561,6 +556,7 @@ pub enum NSISInstallerMode { /// Install the app by default in a directory that doesn't require Administrator access. /// /// Installer metadata will be saved under the `HKCU` registry path. + #[default] CurrentUser, /// Install the app by default in the `Program Files` folder directory requires Administrator /// access for the installation. @@ -575,12 +571,6 @@ pub enum NSISInstallerMode { Both, } -impl Default for NSISInstallerMode { - fn default() -> Self { - Self::CurrentUser - } -} - /// Install modes for the Webview2 runtime. /// Note that for the updater bundle [`Self::DownloadBootstrapper`] is used. /// @@ -2393,11 +2383,12 @@ impl Allowlist for AllowlistConfig { /// The application pattern. #[skip_serializing_none] -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default)] #[serde(rename_all = "lowercase", tag = "use", content = "options")] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum PatternKind { /// Brownfield pattern. + #[default] Brownfield, /// Isolation pattern. Recommended for security purposes. Isolation { @@ -2406,12 +2397,6 @@ pub enum PatternKind { }, } -impl Default for PatternKind { - fn default() -> Self { - Self::Brownfield - } -} - /// The Tauri configuration object. /// /// See more: https://tauri.app/v1/api/config#tauriconfig @@ -2481,7 +2466,7 @@ impl<'de> Deserialize<'de> for UpdaterEndpoint { } /// Install modes for the Windows update. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone, Default)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "schema", schemars(rename_all = "camelCase"))] pub enum WindowsUpdateInstallMode { @@ -2491,6 +2476,7 @@ pub enum WindowsUpdateInstallMode { /// Requires admin privileges if the installer does. Quiet, /// Specifies unattended mode, which means the installation only shows a progress bar. + #[default] Passive, // to add more modes, we need to check if the updater relaunch makes sense // i.e. for a full UI mode, the user can also mark the installer to start the app @@ -2510,12 +2496,6 @@ impl Display for WindowsUpdateInstallMode { } } -impl Default for WindowsUpdateInstallMode { - fn default() -> Self { - Self::Passive - } -} - impl Serialize for WindowsUpdateInstallMode { fn serialize(&self, serializer: S) -> std::result::Result where @@ -2989,10 +2969,11 @@ fn default_build() -> BuildConfig { } /// How the window title bar should be displayed on macOS. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Default)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum TitleBarStyle { /// A normal title bar. + #[default] Visible, /// Makes the title bar transparent, so the window background color is shown instead. /// @@ -3007,12 +2988,6 @@ pub enum TitleBarStyle { Overlay, } -impl Default for TitleBarStyle { - fn default() -> Self { - Self::Visible - } -} - impl Serialize for TitleBarStyle { fn serialize(&self, serializer: S) -> std::result::Result where diff --git a/crates/tauri-utils/src/html.rs b/crates/tauri-utils/src/html.rs index d29a61d0897b..958ce597832f 100644 --- a/crates/tauri-utils/src/html.rs +++ b/crates/tauri-utils/src/html.rs @@ -211,21 +211,16 @@ impl From<&PatternKind> for PatternObject { } /// Where the JavaScript is injected to -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Default)] #[serde(rename_all = "lowercase")] pub enum IsolationSide { /// Original frame, the Brownfield application + #[default] Original, /// Secure frame, the isolation security application Secure, } -impl Default for IsolationSide { - fn default() -> Self { - Self::Original - } -} - /// Injects the Isolation JavaScript to a codegen time document. /// /// Note: This function is not considered part of the stable API. diff --git a/crates/tauri-utils/src/lib.rs b/crates/tauri-utils/src/lib.rs index e10b24612269..25e5a4f97db7 100644 --- a/crates/tauri-utils/src/lib.rs +++ b/crates/tauri-utils/src/lib.rs @@ -157,11 +157,12 @@ mod window_effects { pub use window_effects::{WindowEffect, WindowEffectState}; /// How the window title bar should be displayed on macOS. -#[derive(Debug, Clone, PartialEq, Eq, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, Copy, Default)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] #[non_exhaustive] pub enum TitleBarStyle { /// A normal title bar. + #[default] Visible, /// Makes the title bar transparent, so the window background color is shown instead. /// @@ -176,12 +177,6 @@ pub enum TitleBarStyle { Overlay, } -impl Default for TitleBarStyle { - fn default() -> Self { - Self::Visible - } -} - impl Serialize for TitleBarStyle { fn serialize(&self, serializer: S) -> std::result::Result where diff --git a/crates/tauri/src/pattern.rs b/crates/tauri/src/pattern.rs index 5048e86e0dce..c68514b2ee46 100644 --- a/crates/tauri/src/pattern.rs +++ b/crates/tauri/src/pattern.rs @@ -64,10 +64,11 @@ impl From<&Pattern> for PatternObject { /// Where the JavaScript is injected to #[cfg(feature = "isolation")] -#[derive(Debug, Serialize)] +#[derive(Default, Debug, Serialize)] #[serde(rename_all = "lowercase")] pub(crate) enum IsolationSide { /// Original frame, the Brownfield application + #[default] Original, /// Secure frame, the isolation security application #[allow(dead_code)] @@ -75,12 +76,6 @@ pub(crate) enum IsolationSide { } #[cfg(feature = "isolation")] -impl Default for IsolationSide { - fn default() -> Self { - Self::Original - } -} - #[derive(Template)] #[default_template("../scripts/pattern.js")] pub(crate) struct PatternJavascript { diff --git a/crates/tauri/src/tray/mod.rs b/crates/tauri/src/tray/mod.rs index 3f487b0102e6..5ecef674a709 100644 --- a/crates/tauri/src/tray/mod.rs +++ b/crates/tauri/src/tray/mod.rs @@ -19,20 +19,15 @@ use std::path::Path; pub use tray_icon::TrayIconId; /// Describes the mouse button state. -#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize)] +#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, Serialize)] pub enum MouseButtonState { /// Mouse button pressed. + #[default] Up, /// Mouse button released. Down, } -impl Default for MouseButtonState { - fn default() -> Self { - Self::Up - } -} - impl From for MouseButtonState { fn from(value: tray_icon::MouseButtonState) -> Self { match value { @@ -43,9 +38,10 @@ impl From for MouseButtonState { } /// Describes which mouse button triggered the event.. -#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Default)] pub enum MouseButton { /// Left mouse button. + #[default] Left, /// Right mouse button. Right, @@ -53,12 +49,6 @@ pub enum MouseButton { Middle, } -impl Default for MouseButton { - fn default() -> Self { - Self::Left - } -} - impl From for MouseButton { fn from(value: tray_icon::MouseButton) -> Self { match value { From be3dbacfc2d094eb2c74f7ecdadacffa397a89c4 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 31 Oct 2025 17:25:31 +0800 Subject: [PATCH 2/2] Fix left over `#[cfg(feature = "isolation")]` --- crates/tauri/src/pattern.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/tauri/src/pattern.rs b/crates/tauri/src/pattern.rs index c68514b2ee46..c88f11ab30ac 100644 --- a/crates/tauri/src/pattern.rs +++ b/crates/tauri/src/pattern.rs @@ -75,7 +75,6 @@ pub(crate) enum IsolationSide { Secure, } -#[cfg(feature = "isolation")] #[derive(Template)] #[default_template("../scripts/pattern.js")] pub(crate) struct PatternJavascript {