-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestcode.rs
More file actions
1043 lines (871 loc) · 65 KB
/
Copy pathtestcode.rs
File metadata and controls
1043 lines (871 loc) · 65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // use std::fmt;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Cat {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // name: String,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // age: u8,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl fmt::Display for Cat {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // write!(f, "{} is a cat who is {} years old.", self.name, self.age)
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn print_cats(pet: String) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!("{}", pet);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // let mr_mantle = Cat {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // name: "Reggie Mantle".to_string(),
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // age: 4,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // };
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // print_cats(mr_mantle.to_string());
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // "Mr. Mantle's String is {} letters long.",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // mr_mantle.to_string().chars().count()
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Monster {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // health: i32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Wizard {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // health: i32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Ranger {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // health: i32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // trait FightClose: std::fmt::Debug {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn attack_with_sword(&self, opponent: &mut Monster) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health -= 10;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // "You attack with your sword. Your opponent now has {} health left. You are now at: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health, self
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn attack_with_hand(&self, opponent: &mut Monster) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health -= 2;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // "You attack with your hand. your opponent now has {} health left. You are now at: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health, self
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl FightClose for Wizard {}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl FightClose for Ranger {}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // trait FightFromDistance: std::fmt::Debug {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn attack_with_bow(&self, opponent: &mut Monster, distance: u32) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // if distance < 10 {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health -= 10;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // "You attack with your bow. your opponent now has {} health left. You are now at: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health, self
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn attack_with_rock(&self, opponent: &mut Monster, distance: u32) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // if distance < 3 {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health -= 4;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // "You attack with your rock. your opponent now has {} health left. You are now at: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health, self
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl FightFromDistance for Ranger {}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // let radagast = Wizard { health: 60 };
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // let aragorn = Ranger { health: 80 };
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // let mut uruk_hai = Monster { health: 40 };
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // radagast.attack_with_sword(&mut uruk_hai);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // aragorn.attack_with_bow(&mut uruk_hai, 8);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // use std::fmt::Debug; // So we don't have to write std::fmt::Debug every time now
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Monster {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // health: i32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Wizard {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // health: i32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Ranger {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // health: i32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // trait Magic {} // No methods for any of these traits. They are just trait bounds
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // trait FightClose {}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // trait FightFromDistance {}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl FightClose for Ranger {} // Each type gets FightClose,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl FightClose for Wizard {}
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl FightFromDistance for Ranger {} // but only Ranger gets FightFromDistance
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // impl Magic for Wizard {} // and only Wizard gets Magic
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn attack_with_bow<T: FightFromDistance + Debug>(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // character: &T,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent: &mut Monster,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // distance: u32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // ) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // if distance < 10 {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health -= 10;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // "You attack with your bow. Your opponent now has {} health left. You are now at: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health, character
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn attack_with_sword<T: FightClose + Debug>(character: &T, opponent: &mut Monster) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health -= 10;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // "You attack with your sword. Your opponent now has {} health left. You are now at: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health, character
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn fireball<T: Magic + Debug>(character: &T, opponent: &mut Monster, distance: u32) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // if distance < 15 {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health -= 20;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!("You raise your hands and cast a fireball! Your opponent now has {} health left. You are now at: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // opponent.health, character);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // let radagast = Wizard { health: 60 };
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // let aragorn = Ranger { health: 80 };
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // let mut uruk_hai = Monster { health: 40 };
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // attack_with_sword(&radagast, &mut uruk_hai);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // attack_with_bow(&aragorn, &mut uruk_hai, 8);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // fireball(&radagast, &mut uruk_hai, 8);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // use std::fmt::Display;
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn print_vec<T: Display>(input: &Vec<T>) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // for item in input {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // print!("{} ", item);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // println!();
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // let array_vec = Vec::from([8, 9, 10]);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // print_vec(&array_vec);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // let str_vec = Vec::from("What kind of vec will I be?");
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // print_vec(&str_vec);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // let string_vec = Vec::from("What kind of vec will a String be?".to_string());
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // print_vec(&string_vec);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // // // // // // // // // // // // // // // struct City {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // name: String,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // population: u32,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // // // // // // // // // // // // // // // struct Country {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // cities: Vec<City>,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // impl City {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // fn new(name: &str, population: u32) -> Self {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // Self {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // name: name.to_string(),
// // // // // // // // // // // // // // // // // // // // // // // // // // // // population,
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // impl From<Vec<City>> for Country {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // fn from(cities: Vec<City>) -> Self {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // Self { cities }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // impl Country {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // fn print_cities(&self) {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // for city in &self.cities {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // println!("{:?} has a population of {:?}.", city.name, city.population);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // // // let helsinki = City::new("Helsinki", 631_695);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // let turku = City::new("Turku", 186_756);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // let finland_cities = vec![helsinki, turku]; // Vec<City>
// // // // // // // // // // // // // // // // // // // // // // // // // // // // let finland = Country::from(finland_cities); // Country::from
// // // // // // // // // // // // // // // // // // // // // // // // // // // // finland.print_cities();
// // // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // use std::convert::From;
// // // // // // // // // // // // // // // // // // // // // // // // // // // struct EvenOddVec(Vec<Vec<i32>>);
// // // // // // // // // // // // // // // // // // // // // // // // // // // impl From<Vec<i32>> for EvenOddVec {
// // // // // // // // // // // // // // // // // // // // // // // // // // // fn from(input: Vec<i32>) -> Self {
// // // // // // // // // // // // // // // // // // // // // // // // // // // let mut even_odd_vec: Vec<Vec<i32>> = vec![vec![], vec![]]; // vec with two empty vecs
// // // // // // // // // // // // // // // // // // // // // // // // // // // for item in input {
// // // // // // // // // // // // // // // // // // // // // // // // // // // if item % 2 == 0 {
// // // // // // // // // // // // // // // // // // // // // // // // // // // even_odd_vec[0].push(item);
// // // // // // // // // // // // // // // // // // // // // // // // // // // } else {
// // // // // // // // // // // // // // // // // // // // // // // // // // // even_odd_vec[1].push(item);
// // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // Self(even_odd_vec) //return as Self(EvenOddVec)
// // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // // let bunch_of_numbers = vec![8, 7, -1, 222, 9787, -47, 77, 0, 55, 7, 8];
// // // // // // // // // // // // // // // // // // // // // // // // // // // let new_vec = EvenOddVec::from(bunch_of_numbers);
// // // // // // // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // // // // // // "Even numbers: {:?}\nOddnumbers: {:?}",
// // // // // // // // // // // // // // // // // // // // // // // // // // // new_vec.0[0], new_vec.0[1]
// // // // // // // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // use std::fmt::{Debug, Display};
// // // // // // // // // // // // // // // // // // // // // // // // // // fn print_it<T>(input: T)
// // // // // // // // // // // // // // // // // // // // // // // // // // where
// // // // // // // // // // // // // // // // // // // // // // // // // // T: AsRef<str> + Display + Debug,
// // // // // // // // // // // // // // // // // // // // // // // // // // {
// // // // // // // // // // // // // // // // // // // // // // // // // // println!("{}", input);
// // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // print_it("Please print me");
// // // // // // // // // // // // // // // // // // // // // // // // // // print_it("Also, print me".to_string());
// // // // // // // // // // // // // // // // // // // // // // // // // // //print_it(8); // asref 때문에 안됨
// // // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // // // let new_vec = (1..=10).collect::<Vec<i32>>();
// // // // // // // // // // // // // // // // // // // // // // // // // // let new_vec: Vec<i32> = (1..=10).collect();
// // // // // // // // // // // // // // // // // // // // // // // // // let my_vec = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// // // // // // // // // // // // // // // // // // // // // // // // // let new_vec = my_vec.into_iter().skip(3).take(4).collect::<Vec<i32>>();
// // // // // // // // // // // // // // // // // // // // // // // // // println!("{:?}", new_vec);
// // // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug, Clone)]
// // // // // // // // // // // // // // // // // // // // // // // // struct Library {
// // // // // // // // // // // // // // // // // // // // // // // // library_type: LibraryType,
// // // // // // // // // // // // // // // // // // // // // // // // books: Vec<String>,
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // #[derive(Debug, Clone)]
// // // // // // // // // // // // // // // // // // // // // // // // enum LibraryType {
// // // // // // // // // // // // // // // // // // // // // // // // City,
// // // // // // // // // // // // // // // // // // // // // // // // Country,
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // impl Library {
// // // // // // // // // // // // // // // // // // // // // // // // fn add_book(&mut self, book: &str) {
// // // // // // // // // // // // // // // // // // // // // // // // self.books.push(book.to_string());
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // fn new() -> Self {
// // // // // // // // // // // // // // // // // // // // // // // // Self {
// // // // // // // // // // // // // // // // // // // // // // // // library_type: LibraryType::City,
// // // // // // // // // // // // // // // // // // // // // // // // books: Vec::new(),
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // impl Iterator for Library {
// // // // // // // // // // // // // // // // // // // // // // // // type Item = String;
// // // // // // // // // // // // // // // // // // // // // // // // fn next(&mut self) -> Option<String> {
// // // // // // // // // // // // // // // // // // // // // // // // match self.books.pop() {
// // // // // // // // // // // // // // // // // // // // // // // // Some(book) => Some(book + " is found!"),
// // // // // // // // // // // // // // // // // // // // // // // // None => None,
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // // let mut my_library = Library::new();
// // // // // // // // // // // // // // // // // // // // // // // // my_library.add_book("The doom of the Darksword");
// // // // // // // // // // // // // // // // // // // // // // // // my_library.add_book("Demian");
// // // // // // // // // // // // // // // // // // // // // // // // my_library.add_book("구운몽");
// // // // // // // // // // // // // // // // // // // // // // // // my_library.add_book("dlstod");
// // // // // // // // // // // // // // // // // // // // // // // // for item in my_library.clone() {
// // // // // // // // // // // // // // // // // // // // // // // // println!("{}", item);
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // // //lambdas
// // // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // // let num_vec = vec![2, 3, 4];
// // // // // // // // // // // // // // // // // // // // // // // num_vec
// // // // // // // // // // // // // // // // // // // // // // // .iter()
// // // // // // // // // // // // // // // // // // // // // // // .enumerate()
// // // // // // // // // // // // // // // // // // // // // // // .for_each(|(index, number)| println!("Index number {} has number {}.", index, number));
// // // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // // use std::collections::HashMap;
// // // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // // let some_numbers = vec![0, 1, 2, 3, 4, 5]; //Vec<i32>
// // // // // // // // // // // // // // // // // // // // // // let some_words = vec!["zero", "one", "two", "three", "four", "five"]; // Vec<&str>
// // // // // // // // // // // // // // // // // // // // // // let number_word_hashmap: HashMap<_, _> = some_numbers
// // // // // // // // // // // // // // // // // // // // // // .into_iter()
// // // // // // // // // // // // // // // // // // // // // // .zip(some_words.into_iter())
// // // // // // // // // // // // // // // // // // // // // // .collect();
// // // // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // // // "For key {} we get {}.",
// // // // // // // // // // // // // // // // // // // // // // 2,
// // // // // // // // // // // // // // // // // // // // // // number_word_hashmap.get(&2).unwrap()
// // // // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // // let numbers_together = "140399923481800622623218009598281";
// // // // // // // // // // // // // // // // // // // // // for (index, number) in numbers_together.char_indices() {
// // // // // // // // // // // // // // // // // // // // // match (index % 3, number) {
// // // // // // // // // // // // // // // // // // // // // (0..=1, number) => print!("{}", number),
// // // // // // // // // // // // // // // // // // // // // _ => print!("{}\t", number),
// // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // // println!();
// // // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // // let my_vec = vec![8, 9, 10];
// // // // // // // // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // // // // // // // "{:?}",
// // // // // // // // // // // // // // // // // // // // my_vec
// // // // // // // // // // // // // // // // // // // // .iter()
// // // // // // // // // // // // // // // // // // // // .for_each(|_| println!("We didn't use the variables at all"))
// // // // // // // // // // // // // // // // // // // // );
// // // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // // let user_input = vec![
// // // // // // // // // // // // // // // // // // // "8.9",
// // // // // // // // // // // // // // // // // // // "Nine point nine five",
// // // // // // // // // // // // // // // // // // // "8.0",
// // // // // // // // // // // // // // // // // // // "7.6",
// // // // // // // // // // // // // // // // // // // "eleventy_twelve",
// // // // // // // // // // // // // // // // // // // "300",
// // // // // // // // // // // // // // // // // // // ];
// // // // // // // // // // // // // // // // // // // let actual_numbers = user_input
// // // // // // // // // // // // // // // // // // // .into_iter()
// // // // // // // // // // // // // // // // // // // .filter_map(|input| input.parse::<f32>().ok())
// // // // // // // // // // // // // // // // // // // .collect::<Vec<f32>>();
// // // // // // // // // // // // // // // // // // // println!("{:?}", actual_numbers);
// // // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // // let num_vec = vec![10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
// // // // // // // // // // // // // // // // // // println!("{:?}", num_vec.iter().find(|&number| number % 3 == 0)); // find takes a reference, so we give it &number
// // // // // // // // // // // // // // // // // // println!("{:?}", num_vec.iter().find(|&number| number * 2 == 30));
// // // // // // // // // // // // // // // // // // println!("{:?}", num_vec.iter().position(|&number| number % 3 == 0));
// // // // // // // // // // // // // // // // // // println!("{:?}", num_vec.iter().position(|&number| number * 2 == 30));
// // // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // // // // struct Names {
// // // // // // // // // // // // // // // // // one_word: Vec<String>,
// // // // // // // // // // // // // // // // // two_words: Vec<String>,
// // // // // // // // // // // // // // // // // three_words: Vec<String>,
// // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // // let vec_of_names = vec![
// // // // // // // // // // // // // // // // // "Caesar",
// // // // // // // // // // // // // // // // // "Frodo Baggins",
// // // // // // // // // // // // // // // // // "Bilbo Baggins",
// // // // // // // // // // // // // // // // // "Jean-Luc Picard",
// // // // // // // // // // // // // // // // // "Bly Kim",
// // // // // // // // // // // // // // // // // "Data",
// // // // // // // // // // // // // // // // // "Rand AI 'Thor",
// // // // // // // // // // // // // // // // // "Paul Atreides",
// // // // // // // // // // // // // // // // // "Barack Hussein Obama",
// // // // // // // // // // // // // // // // // "Bill Jefferson Clinton",
// // // // // // // // // // // // // // // // // ];
// // // // // // // // // // // // // // // // // let mut iter_of_names = vec_of_names.iter().peekable();
// // // // // // // // // // // // // // // // // let mut all_names = Names {
// // // // // // // // // // // // // // // // // one_word: vec![],
// // // // // // // // // // // // // // // // // two_words: vec![],
// // // // // // // // // // // // // // // // // three_words: vec![],
// // // // // // // // // // // // // // // // // };
// // // // // // // // // // // // // // // // // while iter_of_names.peek().is_some() {
// // // // // // // // // // // // // // // // // let next_item = iter_of_names.next().unwrap();
// // // // // // // // // // // // // // // // // match next_item.match_indices(' ').collect::<Vec<_>>().len() {
// // // // // // // // // // // // // // // // // 0 => all_names.one_word.push(next_item.to_string()),
// // // // // // // // // // // // // // // // // 1 => all_names.two_words.push(next_item.to_string()),
// // // // // // // // // // // // // // // // // _ => all_names.three_words.push(next_item.to_string()),
// // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // // println!("{:?}", all_names);
// // // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // // let new_vec = vec![8, 9, 10];
// // // // // // // // // // // // // // // // let double_vec = new_vec
// // // // // // // // // // // // // // // // .iter()
// // // // // // // // // // // // // // // // .inspect(|first_item| println!("The item is: {}", first_item))
// // // // // // // // // // // // // // // // .map(|x| x * 2)
// // // // // // // // // // // // // // // // .inspect(|next_item| println!("Then it is: {}", next_item))
// // // // // // // // // // // // // // // // .collect::<Vec<i32>>();
// // // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // // // //Lifetimes can be difficult in Rust, but here are some tips to avoid getting too stressed about them:
// // // // // // // // // // // // // // // // // You can stay with owned types, use clones etc. if you want to avoid them for the time being.
// // // // // // // // // // // // // // // // // Much of the time, when the compiler wants a lifetime you will just end up writing <'a> here and there and then it will work. It's just a way of saying "don't worry, I won't give you anything that doesn't live long enough".
// // // // // // // // // // // // // // // // // You can explore lifetimes just a bit at a time. Write some code with owned values, then make one a reference. The compiler will start to complain, but also give some suggestions. And if it gets too complicated, you can undo it and try again next time.
// // // // // // // // // // // // // // // // multiple threads
// // // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // // let mut my_string = String::from("Can I go inside the thread?");
// // // // // // // // // // // // // // // let handle = std::thread::spawn(move || {
// // // // // // // // // // // // // // // println!("{}", my_string);
// // // // // // // // // // // // // // // });
// // // // // // // // // // // // // // // handle.join().unwrap();
// // // // // // // // // // // // // // // }
// // // // // // // // // // // // // // #[derive(Debug)]
// // // // // // // // // // // // // // struct City {
// // // // // // // // // // // // // // name: String,
// // // // // // // // // // // // // // years: Vec<u32>,
// // // // // // // // // // // // // // populations: Vec<u32>,
// // // // // // // // // // // // // // }
// // // // // // // // // // // // // // impl City {
// // // // // // // // // // // // // // fn new(name: &str, years: Vec<u32>, populations: Vec<u32>) -> Self {
// // // // // // // // // // // // // // Self {
// // // // // // // // // // // // // // name: name.to_string(),
// // // // // // // // // // // // // // years,
// // // // // // // // // // // // // // populations,
// // // // // // // // // // // // // // }
// // // // // // // // // // // // // // }
// // // // // // // // // // // // // // fn city_data<F>(&mut self, mut f: F)
// // // // // // // // // // // // // // //f is generic F (closure)
// // // // // // // // // // // // // // where
// // // // // // // // // // // // // // F: FnMut(&mut Vec<u32>, &mut Vec<u32>), //closure takes mut vec u32 (year populations)
// // // // // // // // // // // // // // {
// // // // // // // // // // // // // // f(&mut self.years, &mut self.populations) // this is actual function,
// // // // // // // // // // // // // // }
// // // // // // // // // // // // // // }
// // // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // // let years = vec![
// // // // // // // // // // // // // // 1372, 1834, 1851, 1881, 1897, 1925, 1959, 1989, 2000, 2005, 2010, 2020,
// // // // // // // // // // // // // // ];
// // // // // // // // // // // // // // let populations = vec![
// // // // // // // // // // // // // // 3_250, 15_300, 24_000, 45_900, 58_800, 119_800, 283_071, 478_974, 400_378, 401_694,
// // // // // // // // // // // // // // 406_703, 437_619,
// // // // // // // // // // // // // // ];
// // // // // // // // // // // // // // let mut tallinn = City::new("Tallinn", years, populations);
// // // // // // // // // // // // // // tallinn.city_data(|city_years, city_populations| { //5년 zip print
// // // // // // // // // // // // // // let new_vec = city_years
// // // // // // // // // // // // // // .into_iter()
// // // // // // // // // // // // // // .zip(city_populations.into_iter())
// // // // // // // // // // // // // // .take(5)
// // // // // // // // // // // // // // .collect::<Vec<(_, _)>>();
// // // // // // // // // // // // // // println!("{:?}", new_vec);
// // // // // // // // // // // // // // });
// // // // // // // // // // // // // // tallinn.city_data(|x, y| { //2030,500_000 추가
// // // // // // // // // // // // // // x.push(2030);
// // // // // // // // // // // // // // y.push(500_000);
// // // // // // // // // // // // // // });
// // // // // // // // // // // // // // tallinn.city_data(|x, y| { //1834 data 삭제
// // // // // // // // // // // // // // let position_option = x.iter().position(|x| *x == 1834);
// // // // // // // // // // // // // // if let Some(position) = position_option {
// // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // "Going to delete {} at position {:?} now.",
// // // // // // // // // // // // // // x[position], position
// // // // // // // // // // // // // // );
// // // // // // // // // // // // // // x.remove(position);
// // // // // // // // // // // // // // y.remove(position);
// // // // // // // // // // // // // // }
// // // // // // // // // // // // // // });
// // // // // // // // // // // // // // println!(
// // // // // // // // // // // // // // "Years left are {:?}\nPopulations left are {:?}",
// // // // // // // // // // // // // // tallinn.years, tallinn.populations
// // // // // // // // // // // // // // );
// // // // // // // // // // // // // // }
// // // // // // // // // // // // // //return closure
// // // // // // // // // // // // // fn returns_a_closure(input: &str) -> impl FnMut(i32) -> i32 {
// // // // // // // // // // // // // match input {
// // // // // // // // // // // // // "double" => |mut number| {
// // // // // // // // // // // // // number *= 2;
// // // // // // // // // // // // // println!("Doubling number. Now it is {}", number);
// // // // // // // // // // // // // number
// // // // // // // // // // // // // },
// // // // // // // // // // // // // "triple" => |mut number| {
// // // // // // // // // // // // // number *= 3;
// // // // // // // // // // // // // println!("Tripling number. Now it its {}", number);
// // // // // // // // // // // // // number
// // // // // // // // // // // // // },
// // // // // // // // // // // // // _ => |number| {
// // // // // // // // // // // // // println!("Sorry, it's the same number: {}", number);
// // // // // // // // // // // // // number
// // // // // // // // // // // // // },
// // // // // // // // // // // // // }
// // // // // // // // // // // // // }
// // // // // // // // // // // // // fn main() {
// // // // // // // // // // // // // let my_number = 10;
// // // // // // // // // // // // // let mut doubles = returns_a_closure("double");
// // // // // // // // // // // // // let mut triples = returns_a_closure("triple");
// // // // // // // // // // // // // let mut quadruples = returns_a_closure("quadruple");
// // // // // // // // // // // // // doubles(my_number);
// // // // // // // // // // // // // triples(my_number);
// // // // // // // // // // // // // quadruples(my_number);
// // // // // // // // // // // // // }
// // // // // // // // // // // // enum TimeOfDay {
// // // // // // // // // // // // Dawn,
// // // // // // // // // // // // Day,
// // // // // // // // // // // // Sunset,
// // // // // // // // // // // // Night,
// // // // // // // // // // // // }
// // // // // // // // // // // // fn change_fear(input: TimeOfDay) -> impl FnMut(f64) -> f64 {
// // // // // // // // // // // // use TimeOfDay::*;
// // // // // // // // // // // // match input {
// // // // // // // // // // // // Dawn => |x| {
// // // // // // // // // // // // println!(
// // // // // // // // // // // // "The morning sun has vanquished the horrible night. You no longer feel afraid."
// // // // // // // // // // // // );
// // // // // // // // // // // // println!("Your fear is now {}", x * 0.5);
// // // // // // // // // // // // x * 0.5
// // // // // // // // // // // // },
// // // // // // // // // // // // Day => |x| {
// // // // // // // // // // // // println!("What a nice day. Maybe put your feet up and rest a bit.");
// // // // // // // // // // // // println!("Your fear is now {}", x * 0.2);
// // // // // // // // // // // // x * 0.2
// // // // // // // // // // // // },
// // // // // // // // // // // // Sunset => |x| {
// // // // // // // // // // // // println!("The sun is almost down! This is no good.");
// // // // // // // // // // // // println!("Your fear is now {}", x * 1.4);
// // // // // // // // // // // // x * 1.4
// // // // // // // // // // // // },
// // // // // // // // // // // // Night => |x| {
// // // // // // // // // // // // println!("What a horrible night to have a curse.");
// // // // // // // // // // // // println!("Your fear is now {}", x * 5.0);
// // // // // // // // // // // // x * 5.0
// // // // // // // // // // // // },
// // // // // // // // // // // // }
// // // // // // // // // // // // }
// // // // // // // // // // // // fn main() {
// // // // // // // // // // // // use TimeOfDay::*;
// // // // // // // // // // // // let mut character_fear = 10.0;
// // // // // // // // // // // // let mut daytime = change_fear(Day);
// // // // // // // // // // // // let mut sunset = change_fear(Sunset);
// // // // // // // // // // // // let mut night = change_fear(Night);
// // // // // // // // // // // // let mut morning = change_fear(Dawn);
// // // // // // // // // // // // character_fear = daytime(character_fear);
// // // // // // // // // // // // character_fear = sunset(character_fear);
// // // // // // // // // // // // character_fear = night(character_fear);
// // // // // // // // // // // // character_fear = morning(character_fear);
// // // // // // // // // // // // }
// // // // // // // // // // // use std::sync::{Arc, Mutex};
// // // // // // // // // // // use std::thread::spawn;
// // // // // // // // // // // fn make_arc(number: i32) -> Arc<Mutex<i32>> {
// // // // // // // // // // // Arc::new(Mutex::new(number))
// // // // // // // // // // // }
// // // // // // // // // // // fn new_clone(input: &Arc<Mutex<i32>>) -> Arc<Mutex<i32>> {
// // // // // // // // // // // Arc::clone(&input)
// // // // // // // // // // // }
// // // // // // // // // // // fn main() {
// // // // // // // // // // // let mut handle_vec = vec![];
// // // // // // // // // // // let my_number = make_arc(0);
// // // // // // // // // // // for _ in 0..2 {
// // // // // // // // // // // let my_number_clone = new_clone(&my_number);
// // // // // // // // // // // let handle = spawn(move || {
// // // // // // // // // // // for _ in 0..10 {
// // // // // // // // // // // let mut value_inside = my_number_clone.lock().unwrap();
// // // // // // // // // // // *value_inside += 1;
// // // // // // // // // // // }
// // // // // // // // // // // });
// // // // // // // // // // // handle_vec.push(handle);
// // // // // // // // // // // }
// // // // // // // // // // // handle_vec
// // // // // // // // // // // .into_iter()
// // // // // // // // // // // .for_each(|handle| handle.join().unwrap());
// // // // // // // // // // // println!("{:?}", my_number);
// // // // // // // // // // // }
// // // // // // // // // // // //alalalalalal
// // // // // // // // // // use std::sync::mpsc::channel;
// // // // // // // // // // fn main() {
// // // // // // // // // // let (sender, receiver) = channel();
// // // // // // // // // // let sender_clone = sender.clone();
// // // // // // // // // // let mut handle_vec = vec![];
// // // // // // // // // // let mut results_vec = vec![];
// // // // // // // // // // handle_vec.push(std::thread::spawn(move || {
// // // // // // // // // // sender.send("Send a &str this time").unwrap();
// // // // // // // // // // }));
// // // // // // // // // // handle_vec.push(std::thread::spawn(move || {
// // // // // // // // // // sender_clone.send("And here is another &str").unwrap();
// // // // // // // // // // }));
// // // // // // // // // // for _ in handle_vec {
// // // // // // // // // // results_vec.push(receiver.recv().unwrap());
// // // // // // // // // // }
// // // // // // // // // // println!("{:?}", results_vec);
// // // // // // // // // // }
// // // // // // // // // use std::sync::mpsc::channel;
// // // // // // // // // use std::thread::spawn;
// // // // // // // // // fn main() {
// // // // // // // // // let (sender, receiver) = channel();
// // // // // // // // // let hugevec = vec![0; 1_000_000];
// // // // // // // // // let mut newvec = vec![];
// // // // // // // // // let mut handle_vec = vec![];
// // // // // // // // // for i in 0..10 {
// // // // // // // // // let sender_clone = sender.clone();
// // // // // // // // // let mut work: Vec<u8> = Vec::with_capacity(hugevec.len() / 10);
// // // // // // // // // work.extend(&hugevec[i * 100_000..(i + 1) * 100_000]);
// // // // // // // // // let handle = spawn(move || {
// // // // // // // // // for number in work.iter_mut() {
// // // // // // // // // *number += 1;
// // // // // // // // // }
// // // // // // // // // sender_clone.send(work).unwrap();
// // // // // // // // // });
// // // // // // // // // handle_vec.push(handle);
// // // // // // // // // }
// // // // // // // // // for handle in handle_vec {
// // // // // // // // // handle.join().unwrap();
// // // // // // // // // }
// // // // // // // // // while let Ok(results) = receiver.try_recv() {
// // // // // // // // // newvec.push(results);
// // // // // // // // // }
// // // // // // // // // let newvec = newvec.into_iter().flatten().collect::<Vec<u8>>();
// // // // // // // // // println!(
// // // // // // // // // "{:?}, {:?}, total length: {}",
// // // // // // // // // &newvec[0..10],
// // // // // // // // // &newvec[newvec.len() - 10..newvec.len()],
// // // // // // // // // newvec.len()
// // // // // // // // // );
// // // // // // // // // for number in newvec {
// // // // // // // // // if number != 1 {
// // // // // // // // // panic!();
// // // // // // // // // }
// // // // // // // // // }
// // // // // // // // // }
// // // // // // // // #[derive(Debug)]
// // // // // // // // struct Character {
// // // // // // // // name: String,
// // // // // // // // age: u8,
// // // // // // // // height: u32,
// // // // // // // // weight: u32,
// // // // // // // // lifestate: LifeState,
// // // // // // // // can_use: bool,
// // // // // // // // }
// // // // // // // // #[derive(Debug)]
// // // // // // // // enum LifeState {
// // // // // // // // Alive,
// // // // // // // // Dead,
// // // // // // // // NeverAlive,
// // // // // // // // Uncertain,
// // // // // // // // }
// // // // // // // // impl Character {
// // // // // // // // fn new(name: String, age: u8, height: u32, weight: u32, alive: bool, can_use: bool) -> Self {
// // // // // // // // Self {
// // // // // // // // name,
// // // // // // // // age,
// // // // // // // // height,
// // // // // // // // weight,
// // // // // // // // lifestate: if alive {
// // // // // // // // LifeState::Alive
// // // // // // // // } else {
// // // // // // // // LifeState::Dead
// // // // // // // // },
// // // // // // // // can_use,
// // // // // // // // }
// // // // // // // // }
// // // // // // // // fn height(mut self, height: u32) -> Self {
// // // // // // // // self.height = height;
// // // // // // // // self.can_use = false;
// // // // // // // // self
// // // // // // // // }
// // // // // // // // fn weight(mut self, weight: u32) -> Self {
// // // // // // // // self.weight = weight;
// // // // // // // // self.can_use = false;
// // // // // // // // self
// // // // // // // // }
// // // // // // // // fn name(mut self, name: &str) -> Self {
// // // // // // // // self.name = name.to_string();
// // // // // // // // self.can_use = false;
// // // // // // // // self
// // // // // // // // }
// // // // // // // // fn build(mut self) -> Result<Character, String> {
// // // // // // // // if self.height < 200 && self.weight < 300 && !self.name.to_lowercase().contains("smurf") {
// // // // // // // // self.can_use = true;
// // // // // // // // Ok(self)
// // // // // // // // } else {
// // // // // // // // Err("Could not create character. Characters must have:
// // // // // // // // 1) Height below 200
// // // // // // // // 2) Weight below 300
// // // // // // // // 3) A name that is not Smurf (that is a bad word)"
// // // // // // // // .to_string())
// // // // // // // // }
// // // // // // // // }
// // // // // // // // }
// // // // // // // // impl Default for Character {
// // // // // // // // fn default() -> Self {
// // // // // // // // Self {
// // // // // // // // name: "Billy".to_string(),
// // // // // // // // age: 15,
// // // // // // // // height: 170,
// // // // // // // // weight: 70,
// // // // // // // // lifestate: LifeState::Alive,
// // // // // // // // can_use: true,
// // // // // // // // }
// // // // // // // // }
// // // // // // // // }
// // // // // // // // fn main() {
// // // // // // // // let character_1 = Character::default(); //default를 없애고 기본조건을 new로 옮겨야 한다
// // // // // // // // let character_2 = Character::default().height(180).weight(60).name("Bobby");
// // // // // // // // let character_3 = Character::default().height(500).name("Cathy").build();
// // // // // // // // println!(
// // // // // // // // "The character {:?} is {:?} years old",
// // // // // // // // character_1.name, character_1.age
// // // // // // // // );
// // // // // // // // println!("{:?}", character_2);
// // // // // // // // match character_3 {
// // // // // // // // Ok(character_info) => println!("{:?}", character_info),
// // // // // // // // Err(err_info) => println!("{}", err_info),
// // // // // // // // }
// // // // // // // // println!();
// // // // // // // // }
// // // // // // // // use std::ops::Deref;
// // // // // // // #[derive(Debug)]
// // // // // // // struct HoldsANumber(u8);
// // // // // // // // impl Deref for HoldsANumber {
// // // // // // // // type Target = u8;
// // // // // // // // fn deref(&self) -> &Self::Target {
// // // // // // // // &self.0
// // // // // // // // }
// // // // // // // // }
// // // // // // // fn main() {
// // // // // // // let my_number = HoldsANumber(20);
// // // // // // // println!("{:?}", my_number.0 + 20);
// // // // // // // }
// // // // // // mod country {
// // // // // // fn print_country(country: &str) {
// // // // // // println!("We are in the country of {}", country);
// // // // // // }
// // // // // // pub mod province {
// // // // // // fn print_province(province: &str) {
// // // // // // println!("in the province of {}", province);
// // // // // // }
// // // // // // pub mod city {
// // // // // // use super::super::*;
// // // // // // use super::*;
// // // // // // pub fn print_city(country: &str, province: &str, city: &str) {
// // // // // // print_country(country);
// // // // // // print_province(province);
// // // // // // println!("in the city of {}", city);
// // // // // // }
// // // // // // }
// // // // // // }
// // // // // // }
// // // // // // fn main() {
// // // // // // use crate::country::province::city::print_city;
// // // // // // print_city("Canada", "New Brunswick", "Moncton");
// // // // // // print_city("Korea", "gyeonggi-do", "Gwangju");
// // // // // // }
// // // // // fn return_two() -> i8 {
// // // // // 2
// // // // // }
// // // // // fn return_six() -> i8 {
// // // // // 4 + return_two()
// // // // // }
// // // // // #[cfg(test)]
// // // // // mod tests {
// // // // // use super::*;
// // // // // #[test]
// // // // // fn it_returns_six() {
// // // // // assert_eq!(return_six(), 6)
// // // // // }
// // // // // #[test]
// // // // // fn it_returns_two() {
// // // // // assert_eq(return_two(), 2);
// // // // // }
// // // // // }
// // // // use rand::{thread_rng, Rng};
// // // // use std::fmt;
// // // // struct Character {
// // // // strength: u8,
// // // // dexterity: u8,
// // // // constitution: u8,
// // // // intelligence: u8,
// // // // wisdom: u8,
// // // // charisma: u8,
// // // // }
// // // // fn three_die_six() -> u8 {
// // // // let mut generator = thread_rng();
// // // // let mut stat = 0;
// // // // for _ in 0..3 {
// // // // stat += generator.gen_range(1..=6);
// // // // }
// // // // stat
// // // // }
// // // // fn four_die_six() -> u8 {
// // // // let mut generator = thread_rng();
// // // // let mut results = vec![];
// // // // for _ in 0..4 {
// // // // results.push(generator.gen_range(1..=6));
// // // // }
// // // // results.sort();
// // // // results.remove(0);
// // // // results.iter().sum()
// // // // }
// // // // enum Dice {
// // // // Three,
// // // // Four,
// // // // }
// // // // impl Character {
// // // // fn new(dice: Dice) -> Self {
// // // // match dice {
// // // // Dice::Three => Self {
// // // // strength: three_die_six(),
// // // // dexterity: three_die_six(),
// // // // constitution: three_die_six(),
// // // // intelligence: three_die_six(),
// // // // wisdom: three_die_six(),
// // // // charisma: three_die_six(),
// // // // },
// // // // Dice::Four => Self {
// // // // strength: four_die_six(),
// // // // dexterity: four_die_six(),
// // // // constitution: four_die_six(),
// // // // intelligence: four_die_six(),
// // // // wisdom: four_die_six(),
// // // // charisma: four_die_six(),
// // // // },
// // // // }
// // // // }
// // // // fn display(&self) {
// // // // println!("{}", self);
// // // // println!();
// // // // }
// // // // }
// // // // impl fmt::Display for Character {
// // // // fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// // // // write!(
// // // // f,
// // // // "Your character has these stats:
// // // // strength: {}
// // // // dexterity: {}
// // // // constitution: {}
// // // // intelligence: {}
// // // // wisdom: {}
// // // // charisma: {}",
// // // // self.strength,
// // // // self.dexterity,
// // // // self.constitution,
// // // // self.intelligence,
// // // // self.wisdom,
// // // // self.charisma
// // // // )
// // // // }
// // // // }
// // // // fn main() {
// // // // let weak_billy = Character::new(Dice::Three);
// // // // let strong_billy = Character::new(Dice::Four);
// // // // weak_billy.display();
// // // // strong_billy.display();
// // // // }
// // // use rayon::prelude::*;
// // // fn main() {
// // // let mut my_vec = vec![0; 200_000];
// // // my_vec
// // // .par_iter_mut()
// // // .enumerate()
// // // .for_each(|(index, number)| *number += index + 1);
// // // println!("{:?}", &my_vec[5000..5005]);
// // // }
// // //user input