[yew-devel] [PATCH yew-comp 2/3] tree wide: implement `Default` for `new()` functions without parameter
Shannon Sterz
s.sterz at proxmox.com
Tue Jan 14 10:09:39 CET 2025
this allows usage of functions like `unwrap_or_default` for these
types and fixes the clippy lint `new_without_default`.
[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
src/apt_package_manager.rs | 6 ++++++
src/apt_repositories.rs | 6 ++++++
src/configuration/network_view.rs | 6 ++++++
src/rrd_timeframe_selector.rs | 6 ++++++
4 files changed, 24 insertions(+)
diff --git a/src/apt_package_manager.rs b/src/apt_package_manager.rs
index 11d7eb8..18454ed 100644
--- a/src/apt_package_manager.rs
+++ b/src/apt_package_manager.rs
@@ -46,6 +46,12 @@ pub struct AptPackageManager {
pub enable_upgrade: bool,
}
+impl Default for AptPackageManager {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl AptPackageManager {
pub fn new() -> Self {
yew::props!(Self {})
diff --git a/src/apt_repositories.rs b/src/apt_repositories.rs
index 7149545..b671d01e 100644
--- a/src/apt_repositories.rs
+++ b/src/apt_repositories.rs
@@ -49,6 +49,12 @@ pub struct AptRepositories {
pub product: Option<ExistingProduct>,
}
+impl Default for AptRepositories {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl AptRepositories {
pub fn new() -> Self {
yew::props!(Self {})
diff --git a/src/configuration/network_view.rs b/src/configuration/network_view.rs
index fa9f985..d7d519c 100644
--- a/src/configuration/network_view.rs
+++ b/src/configuration/network_view.rs
@@ -52,6 +52,12 @@ async fn apply_changes() -> Result<String, Error> {
#[derive(PartialEq, Properties)]
pub struct NetworkView {}
+impl Default for NetworkView {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl NetworkView {
pub fn new() -> Self {
Self {}
diff --git a/src/rrd_timeframe_selector.rs b/src/rrd_timeframe_selector.rs
index d674f7c..5758a04 100644
--- a/src/rrd_timeframe_selector.rs
+++ b/src/rrd_timeframe_selector.rs
@@ -28,6 +28,12 @@ pub struct RRDTimeframeSelector {
on_change: Option<Callback<RRDTimeframe>>,
}
+impl Default for RRDTimeframeSelector {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl RRDTimeframeSelector {
pub fn new() -> Self {
yew::props!(Self {})
--
2.39.5
More information about the yew-devel
mailing list