Skip to content

Commit 282ea1d

Browse files
authored
Fix clippy::unnecessary_lazy_evaluations since Rust 1.64 (rust-mobile#350)
Rust 1.64 is a bit more strict on requiring `.then_some(...)` here over `.then(|| ...)` with a closure, but the former has only been stabilized in 1.62. No need to be cocky and bump the MSRV, replace it with an `if`-`else` like the rest of the `.exists()` path-checking code around here.
1 parent e31aab4 commit 282ea1d

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

ndk-build/src/ndk.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,15 @@ impl Ndk {
309309
} else {
310310
let llvm_bin = format!("llvm-{}{}", name, ext);
311311
let llvm_path = toolchain_path.join(&llvm_bin);
312-
llvm_path
313-
.exists()
314-
.then(|| llvm_path)
315-
.ok_or(NdkError::ToolchainBinaryNotFound {
312+
if llvm_path.exists() {
313+
Ok(llvm_path)
314+
} else {
315+
Err(NdkError::ToolchainBinaryNotFound {
316316
toolchain_path,
317317
gnu_bin,
318318
llvm_bin,
319319
})
320+
}
320321
}
321322
}
322323

ndk/src/media/media_codec.rs

+30-8
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,41 @@ impl MediaFormat {
5555
pub fn i32(&self, key: &str) -> Option<i32> {
5656
let name = CString::new(key).unwrap();
5757
let mut out = 0;
58-
unsafe { ffi::AMediaFormat_getInt32(self.as_ptr(), name.as_ptr(), &mut out) }.then(|| out)
58+
if unsafe { ffi::AMediaFormat_getInt32(self.as_ptr(), name.as_ptr(), &mut out) } {
59+
Some(out)
60+
} else {
61+
None
62+
}
5963
}
6064

6165
pub fn i64(&self, key: &str) -> Option<i64> {
6266
let name = CString::new(key).unwrap();
6367
let mut out = 0;
64-
unsafe { ffi::AMediaFormat_getInt64(self.as_ptr(), name.as_ptr(), &mut out) }.then(|| out)
68+
if unsafe { ffi::AMediaFormat_getInt64(self.as_ptr(), name.as_ptr(), &mut out) } {
69+
Some(out)
70+
} else {
71+
None
72+
}
6573
}
6674

6775
pub fn f32(&self, key: &str) -> Option<f32> {
6876
let name = CString::new(key).unwrap();
6977
let mut out = 0.0;
70-
unsafe { ffi::AMediaFormat_getFloat(self.as_ptr(), name.as_ptr(), &mut out) }.then(|| out)
78+
if unsafe { ffi::AMediaFormat_getFloat(self.as_ptr(), name.as_ptr(), &mut out) } {
79+
Some(out)
80+
} else {
81+
None
82+
}
7183
}
7284

7385
pub fn usize(&self, key: &str) -> Option<usize> {
7486
let name = CString::new(key).unwrap();
7587
let mut out = 0;
76-
unsafe { ffi::AMediaFormat_getSize(self.as_ptr(), name.as_ptr(), &mut out) }
77-
.then(|| out as usize)
88+
if unsafe { ffi::AMediaFormat_getSize(self.as_ptr(), name.as_ptr(), &mut out) } {
89+
Some(out as usize)
90+
} else {
91+
None
92+
}
7893
}
7994

8095
pub fn buffer(&self, key: &str) -> Option<&[u8]> {
@@ -136,7 +151,11 @@ impl MediaFormat {
136151
pub fn f64(&self, key: &str) -> Option<f64> {
137152
let name = CString::new(key).unwrap();
138153
let mut out = 0.0;
139-
unsafe { ffi::AMediaFormat_getDouble(self.as_ptr(), name.as_ptr(), &mut out) }.then(|| out)
154+
if unsafe { ffi::AMediaFormat_getDouble(self.as_ptr(), name.as_ptr(), &mut out) } {
155+
Some(out)
156+
} else {
157+
None
158+
}
140159
}
141160

142161
/// Returns (left, top, right, bottom)
@@ -147,7 +166,7 @@ impl MediaFormat {
147166
let mut top = 0;
148167
let mut right = 0;
149168
let mut bottom = 0;
150-
unsafe {
169+
if unsafe {
151170
ffi::AMediaFormat_getRect(
152171
self.as_ptr(),
153172
name.as_ptr(),
@@ -156,8 +175,11 @@ impl MediaFormat {
156175
&mut right,
157176
&mut bottom,
158177
)
178+
} {
179+
Some((left, top, right, bottom))
180+
} else {
181+
None
159182
}
160-
.then(|| (left, top, right, bottom))
161183
}
162184

163185
#[cfg(feature = "api-level-28")]

0 commit comments

Comments
 (0)