Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Point {
- x: f64,
- y: f64,
- }
- fn point_new(x: f64, y: f64) -> Point {
- Point{ x: x, y: y }
- }
- fn point_get_x(p: & Point) -> f64 {
- (*p).x
- }
- fn point_get_y(p: & Point) -> f64 {
- (*p).y
- }
- fn point_set_x(p: &mut Point, x: f64) {
- (*p).x = x;
- }
- fn point_set_y(p: &mut Point, y: f64) {
- (*p).y = y;
- }
- fn point_to_string(p: & Point) -> String {
- format!("({}, {})", point_get_x(p), point_get_y(p))
- }
- fn main() {
- let mut p = point_new(0.0, 0.0);
- assert_eq!(point_to_string(&p), "(0, 0)");
- point_set_x(&mut p, 3.0);
- point_set_y(&mut p, 4.0);
- assert_eq!(point_to_string(&p), "(3, 4)");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement