Guest User

Untitled

a guest
Mar 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. struct A {
  2. a: f32,
  3. b: f32,
  4. }
  5. impl A {
  6. fn new(a: f32, b: f32) -> Self {
  7. A { a, b }
  8. }
  9. fn dist(&self, other: &A) -> f32 {
  10. ((self.a - other.a).powi(2) + (self.b - other.b).powi(2)).sqrt()
  11. }
  12. }
  13. fn main() {
  14. let mut v: Vec<A> = Vec::new();
  15. v.push(A::new(5.0,8.0));
  16. v.push(A::new(1.0,32.0));
  17. v.push(A::new(91.0,4.0));
  18. let dist = v[0].dist(&v[1]);
  19. println!("{}", dist);
  20. }
Add Comment
Please, Sign In to add comment