How do I fix “wrong number of type arguments” while trying to implement a method?

前端 未结 1 369
再見小時候
再見小時候 2021-01-25 01:22

I\'m trying to implement a method:

struct Point {
    x: T,
    y: T,
}

struct Line {
    start: Point,
    end: Point,
}

i         


        
相关标签:
1条回答
  • 2021-01-25 01:44

    You need to add a type parameter to the impl:

    impl Line<f64> {
        fn length(&self) -> f64 {
            let dx: f64 = self.start.x - self.end.x;
            let dy: f64 = self.start.y - self.end.y;
            (dx * dx + dy * dy).sqrt()
        }
    }
    
    0 讨论(0)
提交回复
热议问题