Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct A {
- a: f32,
- b: f32,
- }
- impl A {
- fn new(a: f32, b: f32) -> Self {
- A { a, b }
- }
- fn dist(&self, other: &A) -> f32 {
- ((self.a - other.a).powi(2) + (self.b - other.b).powi(2)).sqrt()
- }
- }
- fn main() {
- let mut v: Vec<A> = Vec::new();
- v.push(A::new(5.0,8.0));
- v.push(A::new(1.0,32.0));
- v.push(A::new(91.0,4.0));
- let dist = v[0].dist(&v[1]);
- println!("{}", dist);
- }
Add Comment
Please, Sign In to add comment