Answer the question
In order to leave comments, you need to log in
How to restrict type T to primitive types f32 and f64?
in short then
impl<T> Compute<T> for Astra
where T:f32 +f64
{
fn compute(&self, input: &mut Matrix<T>) -> Matrix<T> {
// Что то делать
}
}
<T>
is unknown, it (the compiler) <T>
impl<T> Compute<T> for f64
{
fn compute(&self, input: &mut Matrix<T>) -> Matrix<T> {
// Что то делать
}
}
Answer the question
In order to leave comments, you need to log in
You can restrict a generic type to only traits.
What do you want to do? What methods f32 and f64 do you need?
Perhaps these methods are already implemented in the traits of the standard library - then you need to limit them to the amount.
Another option is to make your own trait, restrict the generic type to it, implement this trait for f32 and f64
Implementation should represent wrappers over the necessary actions
UPD: if you need a generic restriction, to use the exp method for f32 and f64: Trait
contract for the exp method:
trait Exp {
fn exp(self) -> Self;
}
impl Exp for f32 {
fn exp(self) -> Self {
<f32>::exp(self)
}
}
impl Exp for f64 {
fn exp(self) -> Self {
<f64>::exp(self)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question