Help with generics and lifetime

use std::ops::Mul;

pub trait TraitWithGeneric<T> {
    fn evaluate(&self) ->T;
}

pub struct ImplStruct<T> {
    v:T
}

impl<T> TraitWithGeneric<T> for ImplStruct<T>
where
    T:Mul<f32, Output=T>,
    T:Copy
{
    fn evaluate(&self) -> T {
        self.v * 1.2
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 4.69s

Hi, everyone
the above code sample works fine, but I want to know if the T has no Copy traits supported and only &T: Mul<f32, Output=T>, what should I do? Thanks.

for<'a> &'a T: Mul<…> should work, like this.

Thanks very much, it worked. Higher-ranked trait bounds,

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.