Skip to content

Seal HasAfEnum, Fromf64 and extended traits #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 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
25 changes: 22 additions & 3 deletions src/core/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ impl From<u32> for ColorMap {
}
}

mod private {
pub trait Sealed {}

impl Sealed for num::complex::Complex<f32> {}
impl Sealed for num::complex::Complex<f64> {}
impl Sealed for f32 {}
impl Sealed for f64 {}
impl Sealed for bool {}
impl Sealed for u8 {}
impl Sealed for i16 {}
impl Sealed for u16 {}
impl Sealed for half::f16 {}
impl Sealed for i32 {}
impl Sealed for u32 {}
impl Sealed for i64 {}
impl Sealed for u64 {}
impl Sealed for usize {}
}

/// Types of the data that can be generated using ArrayFire data generation functions.
///
/// The trait HasAfEnum has been defined internally for the following types. We strongly suggest
Expand All @@ -139,7 +158,7 @@ impl From<u32> for ColorMap {
/// - i16
/// - u16
///
pub trait HasAfEnum {
pub trait HasAfEnum: private::Sealed {
/// This type alias points to `Self` always.
type InType: HasAfEnum;
/// This type alias points to the data type used to hold real part of a
Expand Down Expand Up @@ -795,7 +814,7 @@ impl BitOr for MatProp {
/// Trait to convert reduction's scalar output to appropriate output type
///
/// This is an internal trait and ideally of no use to user usecases.
pub trait Fromf64 {
pub trait Fromf64: private::Sealed {
/// Convert to target type from a double precision value
fn fromf64(value: f64) -> Self;
}
Expand Down Expand Up @@ -837,7 +856,7 @@ impl IndexableType for u16 {}
impl IndexableType for u8 {}

/// Trait qualifier for given type indicating computability of covariance
pub trait IntegralType {}
pub trait IntegralType: HasAfEnum {}

impl IntegralType for i64 {}
impl IntegralType for u64 {}
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
//!
//! Please go through our [tutorials](http://arrayfire.org/arrayfire-rust/book/index.html) book for
//! more explanations on how to use ArrayFire to speedup your code.
//!
//! Note that the public traits on arrayfire-rust crate aren't meant to be implemented for user
//! defined types. If attempted, rust compiler will throw an error.

#![doc(
html_logo_url = "http://www.arrayfire.com/logos/arrayfire_logo_symbol.png",
Expand Down