-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements a different approach to converting between types and Datatype dependent type checks. The main idea here that's different than previously is that the DomainType enforced a 1:1 correspondence between TileDB's Datatype enumeration and the Rust type system. Unfortunately, multiple TileDB Datatypes map to the same Rust type. The idea here is to separate the conversion of types and the validation that a given Rust type is valid for a given TileDB Datatype. The basic idea is to move type conversion between Rust and FFI types (i.e., i32 -> uint32_t) to be a separate concern from "Is an i32 valid as a Datatype::Blob". The type conversions basically map directly to how DomainType worked. The validation is moved to a generic method on Datatype in tiledb-sys that makes heavy use of `std::any::TypeId` to restrict the generic type paramter to specific Datatype enum variants.
- Loading branch information
Showing
12 changed files
with
335 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
pub trait CAPIConverter { | ||
type CAPIType: Default + Copy; | ||
|
||
fn to_capi(&self) -> Self::CAPIType; | ||
fn to_rust(value: &Self::CAPIType) -> Self; | ||
} | ||
|
||
impl CAPIConverter for i32 { | ||
type CAPIType = std::ffi::c_int; | ||
|
||
fn to_capi(&self) -> Self::CAPIType { | ||
*self as Self::CAPIType | ||
} | ||
|
||
fn to_rust(value: &Self::CAPIType) -> Self { | ||
*value as Self | ||
} | ||
} | ||
|
||
impl CAPIConverter for u32 { | ||
type CAPIType = std::ffi::c_uint; | ||
|
||
fn to_capi(&self) -> Self::CAPIType { | ||
*self as Self::CAPIType | ||
} | ||
|
||
fn to_rust(value: &Self::CAPIType) -> Self { | ||
*value as Self | ||
} | ||
} | ||
|
||
impl CAPIConverter for f64 { | ||
type CAPIType = std::ffi::c_double; | ||
|
||
fn to_capi(&self) -> Self::CAPIType { | ||
*self as Self::CAPIType | ||
} | ||
|
||
fn to_rust(value: &Self::CAPIType) -> Self { | ||
*value as Self | ||
} | ||
} |
Oops, something went wrong.