Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Cleaned up trait usage and added forbid_unsafe to parts #695

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/array/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
bitmap::Bitmap,
buffer::Buffer,
datatypes::{DataType, Field},
types::Index,
};

use super::{new_empty_array, specification::check_offsets, Array};
Expand Down Expand Up @@ -138,12 +137,12 @@ impl MapArray {
pub fn value(&self, i: usize) -> Box<dyn Array> {
let offset = self.offsets[i];
let offset_1 = self.offsets[i + 1];
let length = (offset_1 - offset).to_usize();
let length = (offset_1 - offset) as usize;

// Safety:
// One of the invariants of the struct
// is that offsets are in bounds
unsafe { self.field.slice_unchecked(offset.to_usize(), length) }
unsafe { self.field.slice_unchecked(offset as usize, length) }
}

/// Returns the element at index `i`.
Expand All @@ -153,9 +152,9 @@ impl MapArray {
pub unsafe fn value_unchecked(&self, i: usize) -> Box<dyn Array> {
let offset = *self.offsets.get_unchecked(i);
let offset_1 = *self.offsets.get_unchecked(i + 1);
let length = (offset_1 - offset).to_usize();
let length = (offset_1 - offset) as usize;

self.field.slice_unchecked(offset.to_usize(), length)
self.field.slice_unchecked(offset as usize, length)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/io/avro/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
//! Read and write from and to Apache Avro

pub mod read;
Expand Down
1 change: 1 addition & 0 deletions src/io/csv/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
//! Convert data between the Arrow and CSV (comma-separated values).

use crate::error::ArrowError;
Expand Down
6 changes: 3 additions & 3 deletions src/io/csv/write/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use lexical_core::ToLexical;

use crate::datatypes::IntegerType;
use crate::temporal_conversions;
use crate::types::{Index, NativeType};
use crate::types::NativeType;
use crate::util::lexical_to_bytes_mut;
use crate::{
array::{Array, BinaryArray, BooleanArray, PrimitiveArray, Utf8Array},
Expand Down Expand Up @@ -405,7 +405,7 @@ pub fn new_serializer<'a>(
/// Helper for serializing a dictonary array. The generic parameters are:
/// - `K` for the type of the keys of the dictionary
/// - `O` for the type of the offsets in the Utf8Array: {i32, i64}
fn serialize_utf8_dict<'a, K: DictionaryKey + Index, O: Offset>(
fn serialize_utf8_dict<'a, K: DictionaryKey, O: Offset>(
array: &'a dyn Any,
) -> Box<dyn StreamingIterator<Item = [u8]> + 'a> {
let array = array.downcast_ref::<DictionaryArray<K>>().unwrap();
Expand All @@ -419,7 +419,7 @@ fn serialize_utf8_dict<'a, K: DictionaryKey + Index, O: Offset>(
keys.iter(),
move |x, buf| {
if let Some(x) = x {
let i = Index::to_usize(x);
let i = x.to_usize().unwrap();
if !values.is_null(i) {
let val = values.value(i);
buf.extend_from_slice(val.as_bytes());
Expand Down
7 changes: 1 addition & 6 deletions src/io/ipc/read/array/binary.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::VecDeque;
use std::convert::TryInto;
use std::io::{Read, Seek};

use arrow_format::ipc;
Expand All @@ -8,7 +7,6 @@ use crate::array::{BinaryArray, Offset};
use crate::buffer::Buffer;
use crate::datatypes::DataType;
use crate::error::Result;
use crate::types::NativeType;

use super::super::deserialize::Node;
use super::super::read_basic::*;
Expand All @@ -21,10 +19,7 @@ pub fn read_binary<O: Offset, R: Read + Seek>(
block_offset: u64,
is_little_endian: bool,
compression: Option<ipc::Message::BodyCompression>,
) -> Result<BinaryArray<O>>
where
Vec<u8>: TryInto<O::Bytes> + TryInto<<u8 as NativeType>::Bytes>,
{
) -> Result<BinaryArray<O>> {
let field_node = field_nodes.pop_front().unwrap();

let validity = read_validity(
Expand Down
7 changes: 1 addition & 6 deletions src/io/ipc/read/array/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::VecDeque;
use std::convert::TryInto;
use std::io::{Read, Seek};

use arrow_format::ipc;
Expand All @@ -8,7 +7,6 @@ use crate::array::{Offset, Utf8Array};
use crate::buffer::Buffer;
use crate::datatypes::DataType;
use crate::error::Result;
use crate::types::NativeType;

use super::super::deserialize::Node;
use super::super::read_basic::*;
Expand All @@ -21,10 +19,7 @@ pub fn read_utf8<O: Offset, R: Read + Seek>(
block_offset: u64,
is_little_endian: bool,
compression: Option<ipc::Message::BodyCompression>,
) -> Result<Utf8Array<O>>
where
Vec<u8>: TryInto<O::Bytes> + TryInto<<u8 as NativeType>::Bytes>,
{
) -> Result<Utf8Array<O>> {
let field_node = field_nodes.pop_front().unwrap();

let validity = read_validity(
Expand Down
1 change: 1 addition & 0 deletions src/io/json/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
//! Convert data between the Arrow memory format and JSON line-delimited records.

mod read;
Expand Down