Skip to content

Commit 3c9cc63

Browse files
atomicky9prady9
authored andcommitted
Add HasAfEnum trait bound to associated types
- Simplify `Convertable` trait definition - Force `ImplicitPromote::Output` to be `HasAfEnum`. This is aimed at improving usability for generic code. - Simplify `ConstGenerator` trait definition
1 parent 9ae1ed9 commit 3c9cc63

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

src/core/arith.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,10 @@ pub trait Convertable {
370370
/// This type alias always points to `Self` which is the
371371
/// type of [Array](./struct.Array.html) returned by the
372372
/// trait method [convert](./trait.Convertable.html#tymethod.convert).
373-
type OutType;
373+
type OutType: HasAfEnum;
374374

375375
/// Get an Array of implementors type
376-
fn convert(&self) -> Array<Self::OutType>
377-
where
378-
<Self as Convertable>::OutType: HasAfEnum;
376+
fn convert(&self) -> Array<Self::OutType>;
379377
}
380378

381379
macro_rules! convertable_type_def {

src/core/data.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,14 @@ extern "C" {
126126
///
127127
pub trait ConstGenerator {
128128
/// The type of Array<T> object returned by generate function
129-
type OutType;
129+
type OutType: HasAfEnum;
130130

131131
/// Create an Array of `dims` size from scalar value `self`.
132132
///
133133
/// # Parameters
134134
///
135135
/// - `dims` are the dimensions of the output constant [Array](./struct.Array.html)
136-
fn generate(&self, dims: Dim4) -> Array<Self::OutType>
137-
where
138-
Self::OutType: HasAfEnum;
136+
fn generate(&self, dims: Dim4) -> Array<Self::OutType>;
139137
}
140138

141139
impl ConstGenerator for i64 {

src/core/util.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,27 @@ impl From<u32> for ColorMap {
141141
///
142142
pub trait HasAfEnum {
143143
/// This type alias points to `Self` always.
144-
type InType;
144+
type InType: HasAfEnum;
145145
/// This type alias points to the data type used to hold real part of a
146146
/// complex number. For real valued numbers, this points to `Self`.
147-
type BaseType;
147+
type BaseType: HasAfEnum;
148148
/// This type alias points to `f32` for all 32 bit size types and `f64` for
149149
/// larger 64-bit size types.
150-
type AbsOutType;
150+
type AbsOutType: HasAfEnum;
151151
/// This type alias points to `f64`/`f32` for floating point types and
152152
/// `Self` otherwise.
153-
type ArgOutType;
153+
type ArgOutType: HasAfEnum;
154154
/// This type alias is used to define the output Array type for unary
155155
/// operations. It points to `Self` for floating point types, either
156156
/// real or complex. It points to `f32` for rest of the input types.
157-
type UnaryOutType;
157+
type UnaryOutType: HasAfEnum;
158158
/// This type alias points to complex type created from a given input type.
159159
/// This alias always points to either `std::Complex<f32>` or `std::Complex<f64>`
160160
type ComplexOutType;
161161
/// This type alias points to a data type that can store the mean value for
162162
/// a given input type. This alias points to `f32`/`Complex<f32>` for all 32
163163
/// bit size types and `f64`/`Complex<f64>` for larger 64-bit size types.
164-
type MeanOutType;
164+
type MeanOutType: HasAfEnum;
165165
/// This type alias points to a data type that can store the result of
166166
/// aggregation of set of values for a given input type. Aggregate type
167167
/// alias points to below types for given input types:
@@ -172,17 +172,17 @@ pub trait HasAfEnum {
172172
/// - `u32` for input types: `u16`
173173
/// - `i32` for input types: `i32`
174174
/// - `u32` for input types: `u32`
175-
type AggregateOutType;
175+
type AggregateOutType: HasAfEnum;
176176
/// This type is different for b8 input type
177-
type ProductOutType;
177+
type ProductOutType: HasAfEnum;
178178
/// This type alias points to the output type for given input type of
179179
/// sobel filter operation. Sobel filter output alias points to below
180180
/// types for given input types:
181181
/// - `f32` for input types: `Complex<f32>`, `f32`
182182
/// - `f64` for input types: `Complex<f64>`, `f64`
183183
/// - `i32` for input types: `bool`, `u8`, `i16`, `u16`, `i32`, `u32`
184184
/// - `i64` for input types: `i64`, `u64`
185-
type SobelOutType;
185+
type SobelOutType: HasAfEnum;
186186

187187
/// Return trait implmentors corresponding [DType](./enum.DType.html)
188188
fn get_af_dtype() -> DType;
@@ -427,7 +427,7 @@ impl From<u32> for RandomEngineType {
427427
pub trait ImplicitPromote<RHS> {
428428
/// This type alias points to the type of the result obtained
429429
/// by performing a given binary option on given type and `RHS`.
430-
type Output;
430+
type Output: HasAfEnum;
431431
}
432432

433433
macro_rules! implicit {

0 commit comments

Comments
 (0)