-
I want to make a function that accepts the trait arrayfire::FloatingPoint and produces arrayfire::FloatingPoint. What modifications do I need to make it compile? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@BA8F0D39 I am not sure I understand your use case, the trait you mentioned is more like a Is this what you are trying to achieve ? pub fn addnum(a: &arrayfire::Array<T>,b: &arrayfire::Array<T>) -> arrayfire::Array<T>
where T: FloatingPoint {
a + b
} |
Beta Was this translation helpful? Give feedback.
-
I am new to rust and the rust compiler says cannot find type |
Beta Was this translation helpful? Give feedback.
-
In that case, you should look at https://doc.rust-lang.org/rust-by-example/generics.html
|
Beta Was this translation helpful? Give feedback.
In that case, you should look at https://doc.rust-lang.org/rust-by-example/generics.html
fn foo<T>(arg: T) { ... }
that is how you define a generic function. In this case, the generic typeT
is what reused for defining the generic typeArray<>
that is in turn used a arguments to the function.