Skip to content

Commit

Permalink
Address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
davisp committed Mar 18, 2024
1 parent 9727de9 commit 2dbf2f7
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 73 deletions.
17 changes: 7 additions & 10 deletions examples/quickstart_dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ extern crate tiledb;

use tiledb::Result as TileDBResult;

const QUICKSTART_DENSE_ARRAY_URI: &'static str = "quickstart_dense_array";
const QUICKSTART_ATTRIBUTE_NAME: &'static str = "a";
const QUICKSTART_DENSE_ARRAY_URI: &str = "quickstart_dense_array";
const QUICKSTART_ATTRIBUTE_NAME: &str = "a";

fn array_exists() -> bool {
let tdb = match tiledb::context::Context::new() {
Err(_) => return false,
Ok(tdb) => tdb,
};

if let Ok(Some(tiledb::context::ObjectType::Array)) =
tdb.object_type(QUICKSTART_DENSE_ARRAY_URI)
{
true
} else {
false
}
matches!(
tdb.object_type(QUICKSTART_DENSE_ARRAY_URI),
Ok(Some(tiledb::context::ObjectType::Array))
)
}

fn create_array() -> TileDBResult<()> {
Expand Down Expand Up @@ -111,7 +108,7 @@ fn read_array() -> TileDBResult<()> {
.dimension_range_typed::<i32>(1, &[2, 4])?
.build();

query.submit().map(|_| ());
query.submit()?;

for value in results {
print!("{} ", value)
Expand Down
24 changes: 10 additions & 14 deletions src/array/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ impl<'ctx> Dimension<'ctx> {
// the only errors are possible via mis-use of the C API, which Rust prevents
assert_eq!(ffi::TILEDB_OK, c_ret);

let c_domain: &[DT::CApiType; 2] = unsafe {
std::mem::transmute::<*const std::ffi::c_void, &[DT::CApiType; 2]>(
c_domain_ptr,
)
};
let c_domain: &[DT::CApiType; 2] =
unsafe { &*c_domain_ptr.cast::<[DT::CApiType; 2]>() };

Ok([DT::from_capi(&c_domain[0]), DT::from_capi(&c_domain[1])])
}

Expand Down Expand Up @@ -138,12 +136,10 @@ impl<'ctx> Builder<'ctx> {
c_context,
c_name.as_ptr(),
c_datatype,
std::mem::transmute::<&DT::CApiType, *const std::ffi::c_void>(
&c_domain[0],
),
std::mem::transmute::<&DT::CApiType, *const std::ffi::c_void>(
&c_extent,
),
&c_domain[0] as *const <DT as DomainType>::CApiType
as *const std::ffi::c_void,
&c_extent as *const <DT as DomainType>::CApiType
as *const std::ffi::c_void,
&mut c_dimension,
)
} == ffi::TILEDB_OK
Expand Down Expand Up @@ -179,9 +175,9 @@ impl<'ctx> Builder<'ctx> {
}
}

impl<'ctx> Into<Dimension<'ctx>> for Builder<'ctx> {
fn into(self) -> Dimension<'ctx> {
self.build()
impl<'ctx> From<Builder<'ctx>> for Dimension<'ctx> {
fn from(builder: Builder<'ctx>) -> Dimension<'ctx> {
builder.build()
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/array/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ use crate::Result as TileDBResult;

pub(crate) enum RawDomain {
Owned(*mut ffi::tiledb_domain_t),
Borrowed(*mut ffi::tiledb_domain_t),
}

impl Deref for RawDomain {
type Target = *mut ffi::tiledb_domain_t;
fn deref(&self) -> &Self::Target {
match *self {
RawDomain::Owned(ref ffi) => ffi,
RawDomain::Borrowed(ref ffi) => ffi,
}
}
}

impl Drop for RawDomain {
fn drop(&mut self) {
if let RawDomain::Owned(ref mut ffi) = *self {
unsafe { ffi::tiledb_domain_free(ffi) }
}
let RawDomain::Owned(ref mut ffi) = *self;
unsafe { ffi::tiledb_domain_free(ffi) };
}
}

Expand Down Expand Up @@ -120,9 +117,9 @@ impl<'ctx> Builder<'ctx> {
}
}

impl<'ctx> Into<Domain<'ctx>> for Builder<'ctx> {
fn into(self) -> Domain<'ctx> {
self.build()
impl<'ctx> From<Builder<'ctx>> for Domain<'ctx> {
fn from(builder: Builder<'ctx>) -> Domain<'ctx> {
builder.build()
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/array/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Drop for RawSchema {
pub struct Schema<'ctx> {
context: &'ctx Context,
raw: RawSchema,
domain: Domain<'ctx>,
_domain: Domain<'ctx>,
}

impl<'ctx> Schema<'ctx> {
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'ctx> Builder<'ctx> {
schema: Schema {
context,
raw: RawSchema::new(c_schema),
domain,
_domain: domain,
},
})
}
Expand Down Expand Up @@ -166,9 +166,9 @@ impl<'ctx> Builder<'ctx> {
}
}

impl<'ctx> Into<Schema<'ctx>> for Builder<'ctx> {
fn into(self) -> Schema<'ctx> {
self.build()
impl<'ctx> From<Builder<'ctx>> for Schema<'ctx> {
fn from(builder: Builder<'ctx>) -> Schema<'ctx> {
builder.build()
}
}

Expand All @@ -179,11 +179,11 @@ mod tests {
use crate::context::Context;

/// Helper function to make a Domain which isn't needed for the purposes of the test
fn unused_domain<'ctx>(c: &'ctx Context) -> Domain<'ctx> {
let dim = DimensionBuilder::new::<i32>(&c, "test", &[-100, 100], &100)
fn unused_domain(c: &Context) -> Domain {
let dim = DimensionBuilder::new::<i32>(c, "test", &[-100, 100], &100)
.unwrap()
.build();
DomainBuilder::new(&c)
DomainBuilder::new(c)
.unwrap()
.add_dimension(dim)
.unwrap()
Expand Down
9 changes: 0 additions & 9 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ pub enum ObjectType {
Group,
}

impl ObjectType {
pub(crate) fn capi_enum(&self) -> ffi::tiledb_object_t {
match *self {
ObjectType::Array => ffi::tiledb_object_t_TILEDB_ARRAY,
ObjectType::Group => ffi::tiledb_object_t_TILEDB_GROUP,
}
}
}

pub struct Context {
_wrapped: *mut ffi::tiledb_ctx_t,
}
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ impl Display for Error {
}
}

impl Into<String> for Error {
fn into(self) -> String {
self.get_message()
impl From<Error> for String {
fn from(error: Error) -> String {
error.get_message()
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ impl Deref for RawQuery {

impl Drop for RawQuery {
fn drop(&mut self) {
if let RawQuery::Owned(ref mut ffi) = *self {
unsafe { ffi::tiledb_query_free(ffi) }
}
let RawQuery::Owned(ref mut ffi) = *self;
unsafe { ffi::tiledb_query_free(ffi) };
}
}

Expand Down Expand Up @@ -124,13 +123,10 @@ impl<'ctx> Builder<'ctx> {
let c_query = *self.query.raw;
let c_name = cstring!(name);

let c_bufptr = unsafe {
std::mem::transmute::<&mut DT, *mut std::ffi::c_void>(&mut data[0])
};
let c_bufptr = &mut data[0] as *mut DT as *mut std::ffi::c_void;

let mut c_size = Box::new(
(data.len() * std::mem::size_of::<DT>()).try_into().unwrap(),
);
let mut c_size =
Box::new((std::mem::size_of_val(data)).try_into().unwrap());

// TODO: this is not safe because the C API keeps a pointer to the size
// and may write back to it
Expand All @@ -157,8 +153,8 @@ impl<'ctx> Builder<'ctx> {
}
}

impl<'ctx> Into<Query<'ctx>> for Builder<'ctx> {
fn into(self) -> Query<'ctx> {
self.build()
impl<'ctx> From<Builder<'ctx>> for Query<'ctx> {
fn from(builder: Builder<'ctx>) -> Query<'ctx> {
builder.build()
}
}
13 changes: 4 additions & 9 deletions src/query/subarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ impl Deref for RawSubarray {

impl Drop for RawSubarray {
fn drop(&mut self) {
if let RawSubarray::Owned(ref mut ffi) = *self {
unsafe { ffi::tiledb_subarray_free(ffi) }
}
let RawSubarray::Owned(ref mut ffi) = *self;
unsafe { ffi::tiledb_subarray_free(ffi) };
}
}

Expand Down Expand Up @@ -66,12 +65,8 @@ impl<'ctx> Builder<'ctx> {
let c_context = self.subarray.context.as_mut_ptr();
let c_subarray = *self.subarray.raw;

let c_start: *const std::ffi::c_void = unsafe {
std::mem::transmute::<&DT, *const std::ffi::c_void>(&range[0])
};
let c_end: *const std::ffi::c_void = unsafe {
std::mem::transmute::<&DT, *const std::ffi::c_void>(&range[1])
};
let c_start = &range[0] as *const DT as *const std::ffi::c_void;
let c_end = &range[1] as *const DT as *const std::ffi::c_void;

let c_ret = unsafe {
ffi::tiledb_subarray_add_range(
Expand Down

0 comments on commit 2dbf2f7

Please sign in to comment.