From bfbd813cb2d1d98fe8aad2a75f817a6f63810457 Mon Sep 17 00:00:00 2001 From: logist322 Date: Tue, 12 Oct 2021 18:03:50 +0300 Subject: [PATCH] Finish 1-1 step --- 1_concepts/1_1_default_clone_copy/src/main.rs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/1_concepts/1_1_default_clone_copy/src/main.rs b/1_concepts/1_1_default_clone_copy/src/main.rs index 4722cdb..6cf2e4f 100644 --- a/1_concepts/1_1_default_clone_copy/src/main.rs +++ b/1_concepts/1_1_default_clone_copy/src/main.rs @@ -1,3 +1,29 @@ +mod dots { + #[derive(Debug, Clone, Copy, Default)] + pub struct Point { + pub x: i32, + pub y: i32, + } + + #[derive(Debug, Clone)] + pub struct Polyline { + pub points: Vec + } + + impl Polyline { + pub fn new(points: Vec) -> Self { + if points.len() > 0 { + Polyline {points} + } else { + panic!("Add at least one Point") + } + } + } +} + fn main() { - println!("Implement me!"); + let a = dots::Point {x: 3, y: 2}; + let b = dots::Polyline::new(vec![a]); + + println!("{} {} {:?}", a.x, a.y, b.points); }