Skip to content

Commit af2f86f

Browse files
committed
fix(rust): let-chains
Signed-off-by: if0ne <pavel.agafonov.al@gmail.com>
1 parent 8936386 commit af2f86f

File tree

3 files changed

+50
-48
lines changed

3 files changed

+50
-48
lines changed

rust/driver_manager/src/search.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ enum DriverInitFunc<'a> {
226226
}
227227

228228
/// Allow using [DriverInitFunc] as a function pointer.
229-
impl<'a> ops::Deref for DriverInitFunc<'a> {
229+
impl ops::Deref for DriverInitFunc<'_> {
230230
type Target = FFI_AdbcDriverInitFunc;
231231

232232
fn deref(&self) -> &Self::Target {
@@ -346,10 +346,10 @@ impl<'a> DriverLibrary<'a> {
346346
Ok(SearchHit::new(info.lib_path, library, info.entrypoint))
347347
}
348348

349-
pub(crate) fn derive_entrypoint<'b>(
350-
entrypoint: Option<&'b [u8]>,
349+
pub(crate) fn derive_entrypoint(
350+
entrypoint: Option<&[u8]>,
351351
driver_path: impl AsRef<OsStr>,
352-
) -> Cow<'b, [u8]> {
352+
) -> Cow<'_, [u8]> {
353353
if let Some(entrypoint) = entrypoint {
354354
Cow::Borrowed(entrypoint)
355355
} else {
@@ -788,28 +788,30 @@ fn system_config_dir() -> Option<PathBuf> {
788788

789789
fn get_search_paths(lvls: LoadFlags) -> Vec<PathBuf> {
790790
let mut result = Vec::new();
791-
if lvls & LOAD_FLAG_SEARCH_ENV != 0
792-
&& let Some(paths) = env::var_os("ADBC_DRIVER_PATH")
793-
{
794-
for p in env::split_paths(&paths) {
795-
result.push(p);
791+
if lvls & LOAD_FLAG_SEARCH_ENV != 0 {
792+
if let Some(paths) = env::var_os("ADBC_DRIVER_PATH") {
793+
for p in env::split_paths(&paths) {
794+
result.push(p);
795+
}
796796
}
797797
}
798798

799-
if lvls & LOAD_FLAG_SEARCH_USER != 0
800-
&& let Some(path) = user_config_dir()
801-
&& path.exists()
802-
{
803-
result.push(path);
799+
if lvls & LOAD_FLAG_SEARCH_USER != 0 {
800+
if let Some(path) = user_config_dir() {
801+
if path.exists() {
802+
result.push(path);
803+
}
804+
}
804805
}
805806

806807
// system level for windows is to search the registry keys
807808
#[cfg(not(windows))]
808-
if lvls & LOAD_FLAG_SEARCH_SYSTEM != 0
809-
&& let Some(path) = system_config_dir()
810-
&& path.exists()
811-
{
812-
result.push(path);
809+
if lvls & LOAD_FLAG_SEARCH_SYSTEM != 0 {
810+
if let Some(path) = system_config_dir() {
811+
if path.exists() {
812+
result.push(path);
813+
}
814+
}
813815
}
814816

815817
result
@@ -978,7 +980,7 @@ pub(crate) enum DriverLocator<'a> {
978980
/// Returns `Status::InvalidArguments` if:
979981
/// - The URI has no colon separator
980982
/// - The URI format is invalid
981-
pub(crate) fn parse_driver_uri<'a>(uri: &'a str) -> Result<DriverLocator<'a>> {
983+
pub(crate) fn parse_driver_uri(uri: &'_ str) -> Result<DriverLocator<'_>> {
982984
let idx = uri.find(":").ok_or(Error::with_message_and_status(
983985
format!("Invalid URI: {uri}"),
984986
Status::InvalidArguments,

rust/ffi/src/driver_exporter.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,16 @@ unsafe extern "C" fn release_ffi_driver(
300300
driver: *mut FFI_AdbcDriver,
301301
error: *mut FFI_AdbcError,
302302
) -> AdbcStatusCode {
303-
if let Some(driver) = driver.as_mut()
304-
&& driver.release.take().is_none()
305-
{
306-
check_err!(
307-
Err(Error::with_message_and_status(
308-
"Driver already released",
309-
Status::InvalidState
310-
)),
311-
error
312-
);
303+
if let Some(driver) = driver.as_mut() {
304+
if driver.release.take().is_none() {
305+
check_err!(
306+
Err(Error::with_message_and_status(
307+
"Driver already released",
308+
Status::InvalidState
309+
)),
310+
error
311+
);
312+
}
313313
}
314314
ADBC_STATUS_OK
315315
}

rust/ffi/src/types.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -467,24 +467,24 @@ impl TryFrom<&FFI_AdbcError> for Error {
467467
details: None,
468468
};
469469

470-
if value.vendor_code == constants::ADBC_ERROR_VENDOR_CODE_PRIVATE_DATA
471-
&& let Some(driver) = unsafe { value.private_driver.as_ref() }
472-
{
473-
let get_detail_count = driver_method!(driver, ErrorGetDetailCount);
474-
let get_detail = driver_method!(driver, ErrorGetDetail);
475-
let num_details = unsafe { get_detail_count(value) };
476-
let details = (0..num_details)
477-
.map(|i| unsafe { get_detail(value, i) })
478-
.filter(|d| !d.key.is_null() && !d.value.is_null())
479-
.map(|d| unsafe {
480-
// SAFETY: we assume that C gives us a valid string.
481-
let key = CStr::from_ptr(d.key).to_string_lossy().to_string();
482-
// SAFETY: we assume that C gives us valid data.
483-
let value = std::slice::from_raw_parts(d.value, d.value_length);
484-
(key, value.to_vec())
485-
})
486-
.collect();
487-
error.details = Some(details);
470+
if value.vendor_code == constants::ADBC_ERROR_VENDOR_CODE_PRIVATE_DATA {
471+
if let Some(driver) = unsafe { value.private_driver.as_ref() } {
472+
let get_detail_count = driver_method!(driver, ErrorGetDetailCount);
473+
let get_detail = driver_method!(driver, ErrorGetDetail);
474+
let num_details = unsafe { get_detail_count(value) };
475+
let details = (0..num_details)
476+
.map(|i| unsafe { get_detail(value, i) })
477+
.filter(|d| !d.key.is_null() && !d.value.is_null())
478+
.map(|d| unsafe {
479+
// SAFETY: we assume that C gives us a valid string.
480+
let key = CStr::from_ptr(d.key).to_string_lossy().to_string();
481+
// SAFETY: we assume that C gives us valid data.
482+
let value = std::slice::from_raw_parts(d.value, d.value_length);
483+
(key, value.to_vec())
484+
})
485+
.collect();
486+
error.details = Some(details);
487+
}
488488
}
489489

490490
Ok(error)

0 commit comments

Comments
 (0)