Skip to content

Apache DataFusion SQL Query Engine

ARROW-2396: [Rust] Unify Rust Errors

Maximilian Roosf3d68afba43c
diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index 8589a84314..1e1afe64b9 100644
--- a/rust/src/datatypes.rs
+++ b/rust/src/datatypes.rs
@@ -18,11 +18,7 @@
use std::fmt;
use serde_json;
use serde_json::Value;
-
-#[derive(Debug, Clone, PartialEq)]
-pub enum ArrowError {
- ParseError(String),
-}
+use super::error::ArrowError;
#[derive(Debug, Clone, PartialEq)]
pub enum DataType {
diff --git a/rust/src/error.rs b/rust/src/error.rs
index d1fb742efe..6a342e0632 100644
--- a/rust/src/error.rs
+++ b/rust/src/error.rs
@@ -15,17 +15,8 @@
// specific language governing permissions and limitations
// under the License.
-use std::convert::*;
-
-#[derive(Debug, Clone)]
-pub struct Error {
- msg: String,
-}
-
-impl From<&'static str> for Error where {
- fn from(msg: &'static str) -> Self {
- Error {
- msg: String::from(msg),
- }
- }
+#[derive(Debug, Clone, PartialEq)]
+pub enum ArrowError {
+ MemoryError(String),
+ ParseError(String),
}
diff --git a/rust/src/memory.rs b/rust/src/memory.rs
index 2e5aaf0f95..41d4c53ee3 100644
--- a/rust/src/memory.rs
+++ b/rust/src/memory.rs
@@ -18,17 +18,19 @@
use libc;
use std::mem;
-use super::error::Error;
+use super::error::ArrowError;
const ALIGNMENT: usize = 64;
-pub fn allocate_aligned(size: i64) -> Result<*const u8, Error> {
+pub fn allocate_aligned(size: i64) -> Result<*const u8, ArrowError> {
unsafe {
let mut page: *mut libc::c_void = mem::uninitialized();
let result = libc::posix_memalign(&mut page, ALIGNMENT, size as usize);
match result {
0 => Ok(mem::transmute::<*mut libc::c_void, *const u8>(page)),
- _ => Err(Error::from("Failed to allocate memory")),
+ _ => Err(ArrowError::MemoryError(format!(
+ "Failed to allocate memory"
+ ))),
}
}
}