Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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? |
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 ? pubfnaddnum(a:&arrayfire::Array<T>,b:&arrayfire::Array<T>) -> arrayfire::Array<T>whereT:FloatingPoint{
a + b
} |
I am new to rust and the rust compiler says cannot find type |
In that case, you should look at https://doc.rust-lang.org/rust-by-example/generics.html
|
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 typeTis what reused for defining the generic typeArray<>that is in turn used a arguments to the function.