From 82168d028a3e37dc9b2b000008a9d0e6f603d242 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Fri, 10 Jan 2025 22:58:53 +0100 Subject: [PATCH] Manual: replace `unwrap_or(false|true, ...)` -> `is_some_and(...)` or comparison --- godot-core/src/builtin/variant/mod.rs | 6 +++--- godot-core/src/meta/args/ref_arg.rs | 2 +- godot-core/src/obj/bounds.rs | 6 ++---- godot-core/src/obj/raw_gd.rs | 3 +-- godot-macros/src/util/mod.rs | 16 ++++++---------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/godot-core/src/builtin/variant/mod.rs b/godot-core/src/builtin/variant/mod.rs index b38510e04..3e7429bf5 100644 --- a/godot-core/src/builtin/variant/mod.rs +++ b/godot-core/src/builtin/variant/mod.rs @@ -453,9 +453,9 @@ impl Drop for Variant { // Variant is not Eq because it can contain floats and other types composed of floats. impl PartialEq for Variant { fn eq(&self, other: &Self) -> bool { - Self::evaluate(self, other, VariantOperator::EQUAL) - .map(|v| v.to::()) - .unwrap_or(false) // if there is no defined conversion, then they are non-equal + Self::evaluate(self, other, VariantOperator::EQUAL) //. + .is_some_and(|v| v.to::()) + // If there is no defined conversion (-> None), then they are non-equal. } } diff --git a/godot-core/src/meta/args/ref_arg.rs b/godot-core/src/meta/args/ref_arg.rs index 8b6d961f3..49042cba3 100644 --- a/godot-core/src/meta/args/ref_arg.rs +++ b/godot-core/src/meta/args/ref_arg.rs @@ -193,6 +193,6 @@ where } fn is_null(&self) -> bool { - self.shared_ref.map(|r| r.is_null()).unwrap_or(true) + self.shared_ref.map_or(true, T::is_null) } } diff --git a/godot-core/src/obj/bounds.rs b/godot-core/src/obj/bounds.rs index 0c5d69414..06bbabc51 100644 --- a/godot-core/src/obj/bounds.rs +++ b/godot-core/src/obj/bounds.rs @@ -272,8 +272,7 @@ impl MemDynamic { /// Check whether dynamic type is ref-counted. fn inherits_refcounted(obj: &RawGd) -> bool { obj.instance_id_unchecked() - .map(|id| id.is_ref_counted()) - .unwrap_or(false) + .is_some_and(|id| id.is_ref_counted()) } } impl Sealed for MemDynamic {} @@ -301,8 +300,7 @@ impl DynMemory for MemDynamic { out!(" MemDyn::dec <{}>", std::any::type_name::()); if obj .instance_id_unchecked() - .map(|id| id.is_ref_counted()) - .unwrap_or(false) + .is_some_and(|id| id.is_ref_counted()) { // Will call `RefCounted::unreference()` which checks for liveness. MemRefCounted::maybe_dec_ref(obj) diff --git a/godot-core/src/obj/raw_gd.rs b/godot-core/src/obj/raw_gd.rs index 1801d5620..e03b817ee 100644 --- a/godot-core/src/obj/raw_gd.rs +++ b/godot-core/src/obj/raw_gd.rs @@ -103,8 +103,7 @@ impl RawGd { pub(crate) fn is_instance_valid(&self) -> bool { self.cached_rtti .as_ref() - .map(|rtti| rtti.instance_id().lookup_validity()) - .unwrap_or(false) + .is_some_and(|rtti| rtti.instance_id().lookup_validity()) } // See use-site for explanation. diff --git a/godot-macros/src/util/mod.rs b/godot-macros/src/util/mod.rs index 702fd85f1..f88525733 100644 --- a/godot-macros/src/util/mod.rs +++ b/godot-macros/src/util/mod.rs @@ -228,19 +228,15 @@ pub(crate) fn path_is_single(path: &[TokenTree], expected: &str) -> bool { pub(crate) fn path_ends_with(path: &[TokenTree], expected: &str) -> bool { // Could also use TypeExpr::as_path(), or fn below this one. - path.last() - .map(|last| last.to_string() == expected) - .unwrap_or(false) + path.last().is_some_and(|last| last.to_string() == expected) } pub(crate) fn path_ends_with_complex(path: &venial::TypeExpr, expected: &str) -> bool { - path.as_path() - .map(|path| { - path.segments - .last() - .is_some_and(|seg| seg.ident == expected) - }) - .unwrap_or(false) + path.as_path().is_some_and(|path| { + path.segments + .last() + .is_some_and(|seg| seg.ident == expected) + }) } pub(crate) fn extract_cfg_attrs(