Skip to content

Commit 6271c6e

Browse files
authored
Use ptr::default in Rust 1.88 (#3896)
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 72bee56 commit 6271c6e

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ keywords = ["vortex"]
5050
license = "Apache-2.0"
5151
readme = "README.md"
5252
repository = "https://github.com/spiraldb/vortex"
53-
rust-version = "1.87"
53+
rust-version = "1.88"
5454
version = "0.1.0"
5555

5656
[workspace.dependencies]

vortex-ffi/src/array.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
//! FFI interface for working with Vortex Arrays.
55
use std::ffi::{c_int, c_void};
6-
use std::ptr;
76

87
use vortex::dtype::half::f16;
98
use vortex::error::{VortexExpect, VortexUnwrap, vortex_err};
109
use vortex::{Array, ToCanonical};
1110

1211
use crate::arc_dyn_wrapper;
1312
use crate::dtype::vx_dtype;
14-
use crate::error::{try_or, vx_error};
13+
use crate::error::{try_or_default, vx_error};
1514

1615
arc_dyn_wrapper!(
1716
/// Base type for all Vortex arrays.
@@ -47,7 +46,7 @@ pub unsafe extern "C-unwind" fn vx_array_get_field(
4746
index: u32,
4847
error_out: *mut *mut vx_error,
4948
) -> *const vx_array {
50-
try_or(error_out, ptr::null(), || {
49+
try_or_default(error_out, || {
5150
let array = vx_array::as_ref(array);
5251

5352
let field_array = array
@@ -69,7 +68,7 @@ pub unsafe extern "C-unwind" fn vx_array_slice(
6968
error_out: *mut *mut vx_error,
7069
) -> *const vx_array {
7170
let array = vx_array::as_ref(array);
72-
try_or(error_out, ptr::null_mut(), || {
71+
try_or_default(error_out, || {
7372
let sliced = array.slice(start as usize, stop as usize)?;
7473
Ok(vx_array::new(sliced))
7574
})
@@ -82,7 +81,7 @@ pub unsafe extern "C-unwind" fn vx_array_is_null(
8281
error_out: *mut *mut vx_error,
8382
) -> bool {
8483
let array = vx_array::as_ref(array);
85-
try_or(error_out, false, || array.is_invalid(index as usize))
84+
try_or_default(error_out, || array.is_invalid(index as usize))
8685
}
8786

8887
#[unsafe(no_mangle)]
@@ -91,7 +90,7 @@ pub unsafe extern "C-unwind" fn vx_array_null_count(
9190
error_out: *mut *mut vx_error,
9291
) -> u32 {
9392
let array = vx_array::as_ref(array);
94-
try_or(error_out, 0, || Ok(array.invalid_count()?.try_into()?))
93+
try_or_default(error_out, || Ok(array.invalid_count()?.try_into()?))
9594
}
9695

9796
macro_rules! ffiarray_get_ptype {

vortex-ffi/src/array_iterator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use vortex::iter::ArrayIterator;
77

88
use crate::array::vx_array;
99
use crate::box_dyn_wrapper;
10-
use crate::error::{try_or, vx_error};
10+
use crate::error::{try_or_default, vx_error};
1111

1212
box_dyn_wrapper!(
1313
/// A Vortex array iterator.
@@ -36,7 +36,7 @@ pub unsafe extern "C-unwind" fn vx_array_iterator_next(
3636
error_out: *mut *mut vx_error,
3737
) -> *const vx_array {
3838
let iter = vx_array_iterator::as_mut(iter);
39-
try_or(error_out, ptr::null_mut(), || {
39+
try_or_default(error_out, || {
4040
let element = iter.next();
4141

4242
if let Some(element) = element {

vortex-ffi/src/error.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ box_wrapper!(
2020
);
2121

2222
#[inline]
23-
pub fn try_or<T>(
23+
pub fn try_or_default<T: Default>(
2424
error_out: *mut *mut vx_error,
25-
on_err: T,
2625
function: impl FnOnce() -> VortexResult<T>,
2726
) -> T {
2827
match function() {
@@ -35,7 +34,7 @@ pub fn try_or<T>(
3534
message: err.to_string().into(),
3635
}));
3736
unsafe { error_out.write(err) };
38-
on_err
37+
T::default()
3938
}
4039
}
4140
}

vortex-ffi/src/file.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
66
use std::ffi::{CStr, c_char, c_int, c_uint, c_ulong};
77
use std::ops::Range;
8+
use std::slice;
89
use std::str::FromStr;
910
use std::sync::{Arc, LazyLock};
10-
use std::{ptr, slice};
1111

1212
use itertools::Itertools;
1313
use object_store::aws::{AmazonS3Builder, AmazonS3ConfigKey};
@@ -28,7 +28,7 @@ use vortex::scan::ScanBuilder;
2828
use crate::array::vx_array;
2929
use crate::array_iterator::vx_array_iterator;
3030
use crate::dtype::vx_dtype;
31-
use crate::error::{try_or, vx_error};
31+
use crate::error::{try_or_default, vx_error};
3232
use crate::session::{FileKey, vx_session};
3333
use crate::{RUNTIME, arc_wrapper, to_string_vec};
3434

@@ -139,7 +139,7 @@ pub unsafe extern "C-unwind" fn vx_file_open_reader(
139139
) -> *const vx_file {
140140
let session = vx_session::as_ref(session);
141141

142-
try_or(error_out, ptr::null_mut(), || {
142+
try_or_default(error_out, || {
143143
let options = unsafe {
144144
options
145145
.as_ref()
@@ -189,7 +189,7 @@ pub unsafe extern "C-unwind" fn vx_file_write_array(
189189
error_out: *mut *mut vx_error,
190190
) {
191191
let array = vx_array::as_ref(array);
192-
try_or(error_out, (), || {
192+
try_or_default(error_out, || {
193193
let path = unsafe { CStr::from_ptr(path).to_str()? };
194194

195195
RUNTIME.block_on(async {
@@ -232,7 +232,7 @@ pub unsafe extern "C-unwind" fn vx_file_can_prune(
232232
filter_expression_len: c_uint,
233233
error_out: *mut *mut vx_error,
234234
) -> bool {
235-
try_or(error_out, false, || {
235+
try_or_default(error_out, || {
236236
let file = vx_file::as_ref(file);
237237
let filter_expr = extract_expression(filter_expression, filter_expression_len)?;
238238
Ok(filter_expr
@@ -249,7 +249,7 @@ pub unsafe extern "C-unwind" fn vx_file_scan(
249249
opts: *const vx_file_scan_options,
250250
error_out: *mut *mut vx_error,
251251
) -> *mut vx_array_iterator {
252-
try_or(error_out, ptr::null_mut(), || {
252+
try_or_default(error_out, || {
253253
let file = vx_file::as_ref(file);
254254

255255
let scan_options = unsafe { opts.as_ref() }.map_or_else(

vortex-ffi/src/sink.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::ffi::{CStr, c_char};
5-
use std::ptr;
65

76
use mpsc::Sender;
87
use tokio::fs::File;
@@ -17,7 +16,7 @@ use vortex::stream::ArrayStreamAdapter;
1716
use crate::RUNTIME;
1817
use crate::array::vx_array;
1918
use crate::dtype::vx_dtype;
20-
use crate::error::{try_or, vx_error};
19+
use crate::error::{try_or_default, vx_error};
2120

2221
#[allow(non_camel_case_types)]
2322
/// The `sink` interface is used to collect array chunks and place them into a resource
@@ -35,7 +34,7 @@ pub unsafe extern "C-unwind" fn vx_array_sink_open_file(
3534
dtype: *const vx_dtype,
3635
error_out: *mut *mut vx_error,
3736
) -> *mut vx_array_sink {
38-
try_or(error_out, ptr::null_mut(), || {
37+
try_or_default(error_out, || {
3938
let path = unsafe { path.as_ref() }.vortex_expect("null path");
4039
let path = unsafe { CStr::from_ptr(path) }
4140
.to_string_lossy()
@@ -66,7 +65,7 @@ pub unsafe extern "C-unwind" fn vx_array_sink_push(
6665
) {
6766
let array = vx_array::as_ref(array);
6867
let sink = unsafe { sink.as_ref().vortex_expect("null array stream") };
69-
try_or(error_out, (), || {
68+
try_or_default(error_out, || {
7069
sink.sink
7170
.blocking_send(Ok(array.clone()))
7271
.map_err(|e| vortex_err!("send error {}", e.to_string()))
@@ -80,7 +79,7 @@ pub unsafe extern "C-unwind" fn vx_array_sink_close(
8079
sink: *mut vx_array_sink,
8180
error_out: *mut *mut vx_error,
8281
) {
83-
try_or(error_out, (), || {
82+
try_or_default(error_out, || {
8483
let vx_array_sink { sink, writer } = *unsafe { Box::from_raw(sink) };
8584
drop(sink);
8685

0 commit comments

Comments
 (0)