Skip to content

Instantly share code, notes, and snippets.

@dacr
Created October 16, 2024 19:54
Show Gist options
  • Save dacr/0c55200436a742ac79911e6d60af61a8 to your computer and use it in GitHub Desktop.
Save dacr/0c55200436a742ac79911e6d60af61a8 to your computer and use it in GitHub Desktop.
hello rust structs / published by https://github.com/dacr/code-examples-manager #1187efee-710d-4f2b-92b5-8d4d3af72bd0/f3e3f518598dcf1fc7002a3acb94586a095e3fa8
#!/usr/bin/env rust-script
// summary : hello rust structs
// keywords : rust, structs, data-class, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 1187efee-710d-4f2b-92b5-8d4d3af72bd0
// created-on : 2024-10-16T09:16:37+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : ./$file
#[derive(Debug)]
struct Point {
x: f64,
y: f64,
}
fn distance(from: Point, to: Point) -> f64 {
let dx = to.x - from.x;
let dy = to.y - from.y;
(dx.powi(2) + dy.powi(2)).sqrt()
}
fn main() {
let point1 = Point { x: 1.2, y: 3.4 };
println!("point {:?}", point1);
let point2 = Point { x: 10.2, y: 4.32 };
println!("distance {}", distance(point1, point2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment