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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
//! # Overview
//!
//! `mem_viewer` is a Rust crate that provides a macro `view_mem!` to view the memory content of an arbitrary variable. It supports viewing memory content of different data types including integers, floating-point numbers, strings, pointers, vectors, boxed variables, and structs.
//!
//! ## Usage
//! 
//! Add the following line to your `Cargo.toml` file:
//! 
//! ```toml
//! [dependencies]
//! mem_viewer = "0.2.1"
//! ```
//! 
//! Then, in your Rust code, you can use the `view_mem!` macro to view the memory content of a variable. Here's an example:
//! 
//! ```rust
//! use mem_viewer::*;
//! 
//! let my_var: u16 = 69;
//! view_mem!(my_var);
//! ```
//! 
//! This will print the memory content of `my_var` to the console.
//! 
//! ## Example Output
//! 
//! ```none
//! ame: my_var
//! Type: u16
//! Addr: 000000719ddfdce6
//! Size: 2 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -------------------Memory Content-----------------
//!  000000719ddfdce6 | 45  | 069 | 01000101 |  E
//!  000000719ddfdce7 | 00  | 000 | 00000000 |  NUL
//! ```
//! 
//! ## Safe Usage
//! For safe mode, you can use the `safe_view_mem!` macro to view the memory content of a variable. Here's an example:
//! ```rust
//! use mem_viewer::*;
//! 
//! let my_var: u16 = 69;
//! safe_view_mem!(&my_var);
//! ```
//! 
//! ## Example Safe Output
//! ```none
//! Name          : &my_var
//! Type          : &u16
//! Addr          : 000000719ddfdce6
//! Size          : 8 bytes
//! Container Ptr : 00000260c1266610
//! Container Len : 2
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 00000260c1266610 | 45  | 069 | 01000101 | E
//! 00000260c1266611 | 00  | 000 | 00000000 | NUL
//! ```
//! 
//! ## License
//!
//! This crate is licensed under the MIT License.
//!
//! ## Contributing
//!
//! Contributions are welcome! If you find any issues or have any suggestions, please open an issue or submit a pull request on [GitHub](https://github.com/ikhwanperwira/mem_viewer).
//!
//! 
//! # Unit Test Report
//! 
//! ## Code:
//! ```rust
//! #[cfg(test)]
//! mod tests {
//!     use super::*;
//! 
//!     /// Display the memopry content of a u16 variable.
//!     fn view_mem_u16(my_u16: u16) -> () {
//!         // Unsafe test
//!         view_mem!(my_u16);
//! 
//!         // Safe test
//!         safe_view_mem!(&my_u16);
//!     }
//! 
//!     /// Displays the memory content of a u64 variable.
//!     fn view_mem_u64(my_u64: u64) -> () {
//!         // Unsafe test
//!         view_mem!(my_u64);
//! 
//!         // Safe test
//!         safe_view_mem!(&my_u64);
//!     }
//! 
//!     /// Displays the memory content of a f32 variable.
//!     fn view_mem_f32(my_f32: f32) -> () {
//!         // Unsafe test
//!         view_mem!(my_f32);
//! 
//!         // Safe test
//!         safe_view_mem!(&my_f32);
//!     }
//! 
//!     /// Displays the memory content of a string variable.
//!     fn view_mem_str(my_str: &str) -> () {
//!         // Unsafe test
//!         view_mem!(my_str); // Print address of the first character of the my_str
//!         view_mem!(*my_str); // Print actual content of my_str
//! 
//!         // Safe test
//!         safe_view_mem!(&my_str);
//!         safe_view_mem!(my_str);
//!     }
//! 
//!     /// Displays the memory content of a pointer.
//!     fn view_mem_ptr<T>(my_ptr: *const T) -> () {
//!         // Unsafe test
//!         view_mem!(my_ptr);
//!         unsafe { view_mem!(*my_ptr); }
//! 
//!         // Safe test
//!         // Parameterized type is not supported for safe view.
//!     }
//! 
//!     /// Displays the memory content of a vector variable.
//!     fn view_mem_vec<T>(my_vec: Vec<T>) -> () {
//!         // Unsafe test
//!         view_mem!(my_vec);
//!         view_mem!(*my_vec);
//! 
//!         // Safe test
//!         // Parameterized type is not supported for safe view.
//!     }
//! 
//!     /// Displays the memory content of a boxed variable.
//!     fn view_mem_box<T>(my_box: Box<T>) -> () {
//!         // Unsafe test
//!         view_mem!(&my_box);
//!         view_mem!(my_box);
//!         view_mem!(*my_box);
//! 
//!         // Safe test
//!         // Parameterized type is not supported for safe view.
//!     }
//! 
//!     /// Displays the memory content of a vector of boxed variables.
//!     fn view_mem_vec_of_box<T>(my_vec_of_box: Vec<Box<T>>) -> () {
//!         // Unsafe test
//!         view_mem!(my_vec_of_box);
//!         view_mem!(*my_vec_of_box);
//!         view_mem!(*my_vec_of_box[0]);
//! 
//!         // Safe test
//!         // Parameterized type is not supported for safe view.
//!     }
//! 
//!     /// Displays the memory content of a struct variable.
//!     fn view_mem_struct<T>(my_struct: T) -> () {
//!         // Unsafe test
//!         view_mem!(&my_struct);
//!         view_mem!(my_struct);
//! 
//!         // Parameterized type is not supported for safe view.
//!     }
//!      
//!     struct MyStruct {
//!         a: u8,
//!         b: u16,
//!         c: u32,
//!     }
//! 
//!     #[derive(Serialize)]
//!     struct MySerializedStruct {
//!         a: u8,
//!         b: u16,
//!         c: u32,
//!     }
//! 
//!     #[test]
//!     fn u16_viewer() {
//!         println!("This should print the memory of the holy number 69.\n");
//!         assert_eq!(view_mem_u16(69), ());
//!     }
//! 
//!     fn u64_viewer() {
//!         println!("This should print the memory of the holy number 69.\n");
//!         assert_eq!(view_mem_u64(69), ());
//!     }
//! 
//!     #[test]
//!     fn f32_viewer() {
//!         println!("This should print the memory of pi in IEEE 754 representation, which is 0x4048f5c3.\n");
//!         assert_eq!(view_mem_f32(3.14), ());
//!     }
//! 
//!     #[test]
//!     fn str_viewer() {
//!         println!("This should print the memory of 'Hello' and its address.\n");
//!         assert_eq!(view_mem_str("Hello"), ());
//!     }
//! 
//!     #[test]
//!     fn ptr_viewer() {
//!         println!("This should print the memory of a pointer.\n");
//!         let my_ptr: *const u8 = &69;
//! 
//!         // Safe test
//!         println!("Currently pointer type is not supported by safe view memory.\n");
//! 
//!         // Unsafe test
//!         assert_eq!(view_mem_ptr(my_ptr), ());
//!     }
//! 
//!     #[test]
//!     fn vec_viewer() {
//!         println!("This should print the memory address of the vector and the memory of its elements.\n");
//!         let my_vec: Vec<u8> = vec![69, 255, 254, 253, 70];
//! 
//!         // Safe test
//!         safe_view_mem!(&my_vec);
//! 
//!         // Unsafe test
//!         assert_eq!(view_mem_vec(my_vec), ());
//!     }
//! 
//!     #[test]
//!     fn box_viewer() {
//!         println!("This should print the memory address of the box and the memory of its value.\n");
//!         let my_box: Box<u8> = Box::new(69);
//! 
//!         // Safe test
//!         safe_view_mem!(&my_box);
//! 
//! 
//!         // Unsafe test
//!         assert_eq!(view_mem_box(my_box), ());
//!     }
//! 
//!     #[test]
//!     fn vec_of_box_viewer() {
//!         println!("This should print the memory address of the vector of boxes and the memory of its elements.\n");
//!         let my_vec_of_box: Vec<Box<u8>> = vec![Box::new(69), Box::new(255), Box::new(254), Box::new(253), Box::new(70)];
//! 
//!         // Safe test
//!         safe_view_mem!(&my_vec_of_box);
//! 
//!         // Unsafe test
//!         assert_eq!(view_mem_vec_of_box(my_vec_of_box), ());
//!     }
//! 
//!     #[test]
//!     fn struct_viewer() {
//!         println!("This should print the memory address of the struct and the memory of its fields.\n");
//!         let my_struct = MyStruct {
//!             a: 69,
//!             b: 255,
//!             c: 70,
//!         };
//! 
//!         let my_serialized_struct = MySerializedStruct {
//!             a: 69,
//!             b: 255,
//!             c: 70,
//!         };
//! 
//!         // Safe test
//!         safe_view_mem!(&my_serialized_struct);
//! 
//!         // Unsafe test
//!         assert_eq!(view_mem_struct(my_struct), ());
//!     }
//! }
//! ```
//! 
//! ## Output:
//! ```none
//! running 8 tests
//! test tests::ptr_viewer ... ok
//! test tests::f32_viewer ... ok
//! test tests::box_viewer ... ok
//! test tests::str_viewer ... ok
//! test tests::struct_viewer ... ok
//! test tests::u16_viewer ... ok
//! test tests::vec_of_box_viewer ... ok
//! test tests::vec_viewer ... ok
//! 
//! successes:
//! 
//! ---- tests::ptr_viewer stdout ----
//! This should print the memory of a pointer.
//! 
//! Currently pointer type is not supported by safe view memory.
//! 
//! Name: my_ptr
//! Type: *const u8
//! Addr: 000000d4ef4fe980
//! Size: 8 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef4fe980 | a8  | 168 | 10101000 |  ...
//!  000000d4ef4fe981 | 33  | 051 | 00110011 |  3
//!  000000d4ef4fe982 | f6  | 246 | 11110110 |  ...
//!  000000d4ef4fe983 | 9e  | 158 | 10011110 |  ...
//!  000000d4ef4fe984 | f7  | 247 | 11110111 |  ...
//!  000000d4ef4fe985 | 7f  | 127 | 01111111 |  DEL
//!  000000d4ef4fe986 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef4fe987 | 00  | 000 | 00000000 |  NUL
//! 
//! Name: *my_ptr
//! Type: u8
//! Addr: 00007ff79ef633a8
//! Size: 1 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  00007ff79ef633a8 | 45  | 069 | 01000101 |  E
//! 
//! 
//! ---- tests::f32_viewer stdout ----
//! This should print the memory of pi in IEEE 754 representation, which is 0x4048f5c3.
//! 
//! Name: my_f32
//! Type: f32
//! Addr: 000000d4ef2fdbb4
//! Size: 4 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef2fdbb4 | c3  | 195 | 11000011 |  ...
//!  000000d4ef2fdbb5 | f5  | 245 | 11110101 |  ...
//!  000000d4ef2fdbb6 | 48  | 072 | 01001000 |  H
//!  000000d4ef2fdbb7 | 40  | 064 | 01000000 |  @
//! 
//! Name         : &my_f32
//! Type         : &f32
//! Addr         : 000000d4ef2fdbb4
//! Size         : 8 bytes
//! Container Ptr: 000002924a085200
//! Container Len: 4
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a085200 | c3  | 195 | 11000011 | UNK
//! 000002924a085201 | f5  | 245 | 11110101 | UNK
//! 000002924a085202 | 48  | 072 | 01001000 | H
//! 000002924a085203 | 40  | 064 | 01000000 | @
//! 
//! 
//! ---- tests::box_viewer stdout ----
//! This should print the memory address of the box and the memory of its value.
//! 
//! Name         : &my_box
//! Type         : &alloc::boxed::Box<u8>
//! Addr         : 000000d4ef0fde48
//! Size         : 8 bytes
//! Container Ptr: 000002924a085210
//! Container Len: 1
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a085210 | 45  | 069 | 01000101 | E
//! 
//! Name: &my_box
//! Type: &alloc::boxed::Box<u8>
//! Addr: 000000d4ef0fd7d8
//! Size: 8 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef0fd8c0 | 38  | 056 | 00111000 |  8
//!  000000d4ef0fd8c1 | d7  | 215 | 11010111 |  ...
//!  000000d4ef0fd8c2 | 0f  | 015 | 00001111 |  SI
//!  000000d4ef0fd8c3 | ef  | 239 | 11101111 |  ...
//!  000000d4ef0fd8c4 | d4  | 212 | 11010100 |  ...
//!  000000d4ef0fd8c5 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fd8c6 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fd8c7 | 00  | 000 | 00000000 |  NUL
//! 
//! Name: my_box
//! Type: alloc::boxed::Box<u8>
//! Addr: 000000d4ef0fd738
//! Size: 8 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef0fd738 | 30  | 048 | 00110000 |  0
//!  000000d4ef0fd739 | 51  | 081 | 01010001 |  Q
//!  000000d4ef0fd73a | 08  | 008 | 00001000 |  BS
//!  000000d4ef0fd73b | 4a  | 074 | 01001010 |  J
//!  000000d4ef0fd73c | 92  | 146 | 10010010 |  ...
//!  000000d4ef0fd73d | 02  | 002 | 00000010 |  STX
//!  000000d4ef0fd73e | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fd73f | 00  | 000 | 00000000 |  NUL
//! 
//! Name: *my_box
//! Type: u8
//! Addr: 000002924a085130
//! Size: 1 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000002924a085130 | 45  | 069 | 01000101 |  E
//! 
//! 
//! ---- tests::str_viewer stdout ----
//! This should print the memory of 'Hello' and its address.
//! 
//! Name: my_str
//! Type: &str
//! Addr: 000000d4ef6fd228
//! Size: 16 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef6fd228 | 48  | 072 | 01001000 |  H
//!  000000d4ef6fd229 | 33  | 051 | 00110011 |  3
//!  000000d4ef6fd22a | f6  | 246 | 11110110 |  ...
//!  000000d4ef6fd22b | 9e  | 158 | 10011110 |  ...
//!  000000d4ef6fd22c | f7  | 247 | 11110111 |  ...
//!  000000d4ef6fd22d | 7f  | 127 | 01111111 |  DEL
//!  000000d4ef6fd22e | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd22f | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd230 | 05  | 005 | 00000101 |  ENQ
//!  000000d4ef6fd231 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd232 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd233 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd234 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd235 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd236 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef6fd237 | 00  | 000 | 00000000 |  NUL
//! 
//! Name: *my_str
//! Type: str
//! Addr: 00007ff79ef63348
//! Size: 5 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  00007ff79ef63348 | 48  | 072 | 01001000 |  H
//!  00007ff79ef63349 | 65  | 101 | 01100101 |  e
//!  00007ff79ef6334a | 6c  | 108 | 01101100 |  l
//!  00007ff79ef6334b | 6c  | 108 | 01101100 |  l
//!  00007ff79ef6334c | 6f  | 111 | 01101111 |  o
//! 
//! Name         : &my_str
//! Type         : &&str
//! Addr         : 000000d4ef6fd228
//! Size         : 8 bytes
//! Container Ptr: 000002924a092bf0
//! Container Len: 5
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a092bf0 | 48  | 072 | 01001000 | H
//! 000002924a092bf1 | 65  | 101 | 01100101 | e
//! 000002924a092bf2 | 6c  | 108 | 01101100 | l
//! 000002924a092bf3 | 6c  | 108 | 01101100 | l
//! 000002924a092bf4 | 6f  | 111 | 01101111 | o
//! 
//! Name         : my_str
//! Type         : &str
//! Addr         : 00007ff79ef63348
//! Size         : 16 bytes
//! Container Ptr: 000002924a092c00
//! Container Len: 5
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a092c00 | 48  | 072 | 01001000 | H
//! 000002924a092c01 | 65  | 101 | 01100101 | e
//! 000002924a092c02 | 6c  | 108 | 01101100 | l
//! 000002924a092c03 | 6c  | 108 | 01101100 | l
//! 000002924a092c04 | 6f  | 111 | 01101111 | o
//! 
//! 
//! ---- tests::struct_viewer stdout ----
//! This should print the memory address of the struct and the memory of its fields.
//! 
//! Name         : &my_serialized_struct
//! Type         : &mem_viewer::tests::MySerializedStruct
//! Addr         : 000000d4ef8fe508
//! Size         : 8 bytes
//! Container Ptr: 000002924a08df10
//! Container Len: 7
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a08df10 | 45  | 069 | 01000101 | E
//! 000002924a08df11 | ff  | 255 | 11111111 | UNK
//! 000002924a08df12 | 00  | 000 | 00000000 | NUL
//! 000002924a08df13 | 46  | 070 | 01000110 | F
//! 000002924a08df14 | 00  | 000 | 00000000 | NUL
//! 000002924a08df15 | 00  | 000 | 00000000 | NUL
//! 000002924a08df16 | 00  | 000 | 00000000 | NUL
//! 
//! Name: &my_struct
//! Type: &mem_viewer::tests::MyStruct
//! Addr: 000000d4ef8fe058
//! Size: 8 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef8fe140 | b0  | 176 | 10110000 |  ...
//!  000000d4ef8fe141 | df  | 223 | 11011111 |  ...
//!  000000d4ef8fe142 | 8f  | 143 | 10001111 |  ...
//!  000000d4ef8fe143 | ef  | 239 | 11101111 |  ...
//!  000000d4ef8fe144 | d4  | 212 | 11010100 |  ...
//!  000000d4ef8fe145 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef8fe146 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef8fe147 | 00  | 000 | 00000000 |  NUL
//! 
//! Name: my_struct
//! Type: mem_viewer::tests::MyStruct
//! Addr: 000000d4ef8fdfb0
//! Size: 8 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef8fdfb0 | 46  | 070 | 01000110 |  F
//!  000000d4ef8fdfb1 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef8fdfb2 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef8fdfb3 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef8fdfb4 | ff  | 255 | 11111111 |  ...
//!  000000d4ef8fdfb5 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef8fdfb6 | 45  | 069 | 01000101 |  E
//!  000000d4ef8fdfb7 | 00  | 000 | 00000000 |  NUL
//! 
//! 
//! ---- tests::u16_viewer stdout ----
//! This should print the memory of the holy number 69.
//! 
//! Name: my_u16
//! Type: u16
//! Addr: 000000d4efafe2a6
//! Size: 2 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4efafe2a6 | 45  | 069 | 01000101 |  E
//!  000000d4efafe2a7 | 00  | 000 | 00000000 |  NUL
//! 
//! Name         : &my_u16
//! Type         : &u16
//! Addr         : 000000d4efafe2a6
//! Size         : 8 bytes
//! Container Ptr: 000002924a085290
//! Container Len: 2
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a085290 | 45  | 069 | 01000101 | E
//! 000002924a085291 | 00  | 000 | 00000000 | NUL
//! 
//! 
//! ---- tests::vec_of_box_viewer stdout ----
//! This should print the memory address of the vector of boxes and the memory of its elements.
//! 
//! Name         : &my_vec_of_box
//! Type         : &alloc::vec::Vec<alloc::boxed::Box<u8>>
//! Addr         : 000000d4ef0fe490
//! Size         : 8 bytes
//! Container Ptr: 000002924a07cd30
//! Container Len: 5
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a07cd30 | 45  | 069 | 01000101 | E
//! 000002924a07cd31 | ff  | 255 | 11111111 | UNK
//! 000002924a07cd32 | fe  | 254 | 11111110 | UNK
//! 000002924a07cd33 | fd  | 253 | 11111101 | UNK
//! 000002924a07cd34 | 46  | 070 | 01000110 | F
//! 
//! Name: my_vec_of_box
//! Type: alloc::vec::Vec<alloc::boxed::Box<u8>>
//! Addr: 000000d4ef0ff030
//! Size: 24 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef0ff030 | 05  | 005 | 00000101 |  ENQ
//!  000000d4ef0ff031 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff032 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff033 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff034 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff035 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff036 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff037 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff038 | 30  | 048 | 00110000 |  0
//!  000000d4ef0ff039 | 2b  | 043 | 00101011 |  +
//!  000000d4ef0ff03a | 08  | 008 | 00001000 |  BS
//!  000000d4ef0ff03b | 4a  | 074 | 01001010 |  J
//!  000000d4ef0ff03c | 92  | 146 | 10010010 |  ...
//!  000000d4ef0ff03d | 02  | 002 | 00000010 |  STX
//!  000000d4ef0ff03e | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff03f | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff040 | 05  | 005 | 00000101 |  ENQ
//!  000000d4ef0ff041 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff042 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff043 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff044 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff045 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff046 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0ff047 | 00  | 000 | 00000000 |  NUL
//! 
//! Name: *my_vec_of_box
//! Type: [alloc::boxed::Box<u8>]
//! Addr: 000002924a082b30
//! Size: 40 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000002924a082b30 | 10  | 016 | 00010000 |  DLE
//!  000002924a082b31 | cd  | 205 | 11001101 |  ...
//!  000002924a082b32 | 07  | 007 | 00000111 |  BEL
//!  000002924a082b33 | 4a  | 074 | 01001010 |  J
//!  000002924a082b34 | 92  | 146 | 10010010 |  ...
//!  000002924a082b35 | 02  | 002 | 00000010 |  STX
//!  000002924a082b36 | 00  | 000 | 00000000 |  NUL
//!  000002924a082b37 | 00  | 000 | 00000000 |  NUL
//!  000002924a082b38 | d0  | 208 | 11010000 |  ...
//!  000002924a082b39 | cc  | 204 | 11001100 |  ...
//!  000002924a082b3a | 07  | 007 | 00000111 |  BEL
//!  000002924a082b3b | 4a  | 074 | 01001010 |  J
//!  000002924a082b3c | 92  | 146 | 10010010 |  ...
//!  000002924a082b3d | 02  | 002 | 00000010 |  STX
//!  000002924a082b3e | 00  | 000 | 00000000 |  NUL
//!  000002924a082b3f | 00  | 000 | 00000000 |  NUL
//!  000002924a082b40 | e0  | 224 | 11100000 |  ...
//!  000002924a082b41 | cc  | 204 | 11001100 |  ...
//!  000002924a082b42 | 07  | 007 | 00000111 |  BEL
//!  000002924a082b43 | 4a  | 074 | 01001010 |  J
//!  000002924a082b44 | 92  | 146 | 10010010 |  ...
//!  000002924a082b45 | 02  | 002 | 00000010 |  STX
//!  000002924a082b46 | 00  | 000 | 00000000 |  NUL
//!  000002924a082b47 | 00  | 000 | 00000000 |  NUL
//!  000002924a082b48 | 40  | 064 | 01000000 |  @
//!  000002924a082b49 | cd  | 205 | 11001101 |  ...
//!  000002924a082b4a | 07  | 007 | 00000111 |  BEL
//!  000002924a082b4b | 4a  | 074 | 01001010 |  J
//!  000002924a082b4c | 92  | 146 | 10010010 |  ...
//!  000002924a082b4d | 02  | 002 | 00000010 |  STX
//!  000002924a082b4e | 00  | 000 | 00000000 |  NUL
//!  000002924a082b4f | 00  | 000 | 00000000 |  NUL
//!  000002924a082b50 | c0  | 192 | 11000000 |  ...
//!  000002924a082b51 | cc  | 204 | 11001100 |  ...
//!  000002924a082b52 | 07  | 007 | 00000111 |  BEL
//!  000002924a082b53 | 4a  | 074 | 01001010 |  J
//!  000002924a082b54 | 92  | 146 | 10010010 |  ...
//!  000002924a082b55 | 02  | 002 | 00000010 |  STX
//!  000002924a082b56 | 00  | 000 | 00000000 |  NUL
//!  000002924a082b57 | 00  | 000 | 00000000 |  NUL
//! 
//! Name: *my_vec_of_box[0]
//! Type: u8
//! Addr: 000002924a07cd10
//! Size: 1 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000002924a07cd10 | 45  | 069 | 01000101 |  E
//! 
//! 
//! ---- tests::vec_viewer stdout ----
//! This should print the memory address of the vector and the memory of its elements.
//! 
//! Name         : &my_vec
//! Type         : &alloc::vec::Vec<u8>
//! Addr         : 000000d4ef0fdf18
//! Size         : 8 bytes
//! Container Ptr: 000002924a0851e0
//! Container Len: 5
//!      Address     | Hex | Dec |    Bin   | ASCII
//! ---------------Container Content---------------
//! 000002924a0851e0 | 45  | 069 | 01000101 | E
//! 000002924a0851e1 | ff  | 255 | 11111111 | UNK
//! 000002924a0851e2 | fe  | 254 | 11111110 | UNK
//! 000002924a0851e3 | fd  | 253 | 11111101 | UNK
//! 000002924a0851e4 | 46  | 070 | 01000110 | F
//! 
//! Name: my_vec
//! Type: alloc::vec::Vec<u8>
//! Addr: 000000d4ef0fea90
//! Size: 24 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000000d4ef0fea90 | 05  | 005 | 00000101 |  ENQ
//!  000000d4ef0fea91 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea92 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea93 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea94 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea95 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea96 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea97 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea98 | 20  | 032 | 00100000 |  SPC
//!  000000d4ef0fea99 | 51  | 081 | 01010001 |  Q
//!  000000d4ef0fea9a | 08  | 008 | 00001000 |  BS
//!  000000d4ef0fea9b | 4a  | 074 | 01001010 |  J
//!  000000d4ef0fea9c | 92  | 146 | 10010010 |  ...
//!  000000d4ef0fea9d | 02  | 002 | 00000010 |  STX
//!  000000d4ef0fea9e | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0fea9f | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0feaa0 | 05  | 005 | 00000101 |  ENQ
//!  000000d4ef0feaa1 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0feaa2 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0feaa3 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0feaa4 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0feaa5 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0feaa6 | 00  | 000 | 00000000 |  NUL
//!  000000d4ef0feaa7 | 00  | 000 | 00000000 |  NUL
//! 
//! Name: *my_vec
//! Type: [u8]
//! Addr: 000002924a085120
//! Size: 5 bytes
//!      Address      | Hex | Dec |    Bin   | ASCII
//! -----------------Memory Content-----------------
//!  000002924a085120 | 45  | 069 | 01000101 |  E
//!  000002924a085121 | ff  | 255 | 11111111 |  ...
//!  000002924a085122 | fe  | 254 | 11111110 |  ...
//!  000002924a085123 | fd  | 253 | 11111101 |  ...
//!  000002924a085124 | 46  | 070 | 01000110 |  F
//! 
//! 
//! 
//! successes:
//!     tests::box_viewer
//!     tests::f32_viewer
//!     tests::ptr_viewer
//!     tests::str_viewer
//!     tests::struct_viewer
//!     tests::u16_viewer
//!     tests::vec_of_box_viewer
//!     tests::vec_viewer
//! 
//! test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
//! ```
//! 

#![allow(dead_code)]
#![allow(unused_assignments)]
pub use bincode::serialize_into;
pub use serde::Serialize;

#[macro_export]
/// Macro to view the memory content of almost any arbitrary variable in safe way
/// 
/// It's safe because it's isolated on container with serializing into `Vec<u8>` by `serde`. Hence, the address and size displayed is not accurate and actually it's virtual address of the container instead of reported by OS.
/// 
/// It supports viewing memory content of different data types including integers, floating-point numbers, strings, vectors, boxed variables, and structs. Except pointer.
/// 
/// For struct, it's mandatory to add `#[derive(Serialize)]` to the struct definition.
/// 
/// For example:
/// ```rust
/// #[derive(Serialize)]
/// struct MyStruct {
///    a: i32,
///    b: f32,
/// }
/// ```
/// 
/// # Argument
/// 
/// * `&var` - The variable whose memory content needs to be viewed.
/// 
/// # Example
/// 
/// ```rust
/// let my_var: u16 = 69;
/// safe_view_mem!(&my_var);
/// ```
/// 
/// # Output
/// 
/// ```none
/// Name: &my_var
/// Type: &u16
/// Addr: 000000acf3bfdc86
/// Size: 8 bytes
/// Container Ptr : 0000027f45f05290
/// Container Len : 2
///      Address     | Hex | Dec |    Bin   | ASCII
/// ---------------Container Content---------------
/// 0000027f45f05290 | 45  | 069 | 01000101 | E
/// 0000027f45f05291 | 00  | 000 | 00000000 | NUL
/// ```
macro_rules! safe_view_mem  {
	($var: expr) => {
        let size = std::mem::size_of_val(&$var);

		// Print variable metadata
		println!("Name         : {}", stringify!($var));
		println!("Type         : {}", _get_type_of($var));
        println!("Addr         : {:016x}", $var as *const _ as *const u8 as usize);
		println!("Size         : {} bytes", size);

		// Isolate on container
		let mut container: Vec<u8> = Vec::new();
		serialize_into(&mut container, $var).unwrap();
		// println!("Container Raw : {:?}", container);
		if container.len() >= 8 && container.len() != size {
			 // If not same, then there is header of serializer with size 8 bytes, exclude it!
			container = (&container[8..]).to_vec();
		}

		// Print container metadata
		// println!("Container Val : {:?}", container);
        println!("Container Ptr: {:016x}", container.as_ptr() as usize);
		println!("Container Len: {}", container.len());

		// Print container content
		println!("     Address     | Hex | Dec |    Bin   | ASCII");
		println!("---------------Container Content---------------");
		// Iterate over Vec<u8>
		for (_, byte) in container.iter().enumerate() {
			let addr = byte as *const u8 as usize;
			let hex = format!("{:02x}", byte);
			let dec = format!("{:03}", byte);
			let bin = format!("{:08b}", byte);
			let ascii = if byte.is_ascii_graphic() {
				format!("{}  ", *byte as char)
			} else {
				match byte {
							0   => "NUL",
							1   => "SOH",
							2   => "STX",
							3   => "ETX",
							4   => "EOT",
							5   => "ENQ",
							6   => "ACK",
							7   => "BEL",
							8   => "BS ",
							9   => "HT ",
							10  => "LF ",
							11  => "VT ",
							12  => "FF ",
							13  => "CR ",
							14  => "SO ",
							15  => "SI ",
							16  => "DLE",
							17  => "DC1",
							18  => "DC2",
							19  => "DC3",
							20  => "DC4",
							21  => "NAK",
							22  => "SYN",
							23  => "ETB",
							24  => "CAN",
							25  => "EM ",
							26  => "SUB",
							27  => "ESC",
							28  => "FS ",
							29  => "GS ",
							30  => "RS ",
							31  => "US ",
							32  => "SPC",
							127 => "DEL",
							_   => "UNK",
					}.to_string()
			};
			println!("{:016x} | {}  | {} | {} | {}", addr, hex, dec, bin, ascii);
		};

		println!();
	}
	}


#[macro_export]
/// Macro to view the memory content of an arbitrary variable.
/// 
/// It supports viewing memory content of different data types including integers, floating-point numbers, strings, pointers, vectors, boxed variables, and structs.
/// 
/// This is more **unsafe** than safe_view_mem! macro, because it directly reads the memory content of the variable.
/// 
/// As a result, it can be used to view the memory content of a pointer.
/// 
/// You can dereference a variable as many as you want as long compiler allows it, of course this is **unsafe** operation.
///
/// # Argument
///
/// * `var` - The variable whose memory content needs to be viewed.
///
/// # Example
///
/// ```rust
/// let my_var: u16 = 69;
/// view_mem!(my_var);
/// ```
/// 
/// # Output
/// 
/// ```none
/// Name: my_var
/// Type: u16
/// Addr: 00000007f88fdc56
/// Size: 2 bytes
///      Address     | Hex | Dec |    Bin   | ASCII
/// -------------------Memory Content-----------------
///  00000007f88fdc56 | 45 | 069 | 01000101 |  E
///  00000007f88fdc57 | 00 | 000 | 00000000 |  NUL
/// ```
macro_rules! view_mem {
    ($var: expr) => {
        // Get the size of the variable
        let size = std::mem::size_of_val(&$var);

        // Print metadata of var: var_name, size, type, separated by a new line for each meta
        println!("Name: {}", stringify!($var));
        _print_type_of(&$var);
        println!("Addr: {:016x}", &$var as *const _ as *const u8 as usize);
        println!("Size: {} bytes", size);

        _show_memory_content(&$var as *const _ as *const u8, size);
    };
}

/// Returns the type of a variable as a string.
/// 
/// (This is supposed to be private usage of safe_view_mem! macro usage.)
/// 
/// # Argument
/// 
/// * `_: T` - The variable whose type needs to be returned.
pub fn _get_type_of<T>(_: T) -> &'static str {
	std::any::type_name::<T>()
}

/// Prints the type of a variable.
///
/// (This is supposed to be private usage for unsafe view_mem! macro usage.)
/// 
/// # Argument
///
/// * `_: T` - The variable whose type needs to be printed.
pub fn _print_type_of<T>(_: T) {
    let type_name = &std::any::type_name::<T>()[1..]; // Remove `&` at first character
    println!("Type: {}", type_name);
}

/// Displays the memory content of a given memory address.
///
/// 
/// (This is supposed to be private usage for unsafe view_mem! macro usage.)
/// 
/// # Arguments
///
/// * `src_ptr` - The memory address to start displaying from.
/// * `len` - The number of bytes to display.
pub fn _show_memory_content(src_ptr: *const u8, len: usize) { // This supposed to be private usage.
    // Display the memory and its value for every byte from src_ptr to src_ptr + len

    let mut ascii_display = String::with_capacity(3);
    let mut ptr: *const u8 = src_ptr;
    let mut value: u8;

    let end: *const u8 = unsafe { src_ptr.add(len) };

    println!("     Address      | Hex | Dec |    Bin   | ASCII");
    println!("-----------------Memory Content-----------------");
    while ptr < end {
        value = unsafe {*ptr};

        print!(" {:016x} | {:02x}  | {:03} | {:08b} |", ptr as usize, value as usize, value as usize, value as usize);

        ascii_display = "...".to_string(); // Not ASCII

        if value.is_ascii() {
            if value.is_ascii_graphic() { // Graphic ASCII
                ascii_display = (value as char).to_string();
            } else {
                ascii_display = match value { // Non-graphic ASCII
                    0   => "NUL",
                    1   => "SOH",
                    2   => "STX",
                    3   => "ETX",
                    4   => "EOT",
                    5   => "ENQ",
                    6   => "ACK",
                    7   => "BEL",
                    8   => "BS ",
                    9   => "HT ",
                    10  => "LF ",
                    11  => "VT ",
                    12  => "FF ",
                    13  => "CR ",
                    14  => "SO ",
                    15  => "SI ",
                    16  => "DLE",
                    17  => "DC1",
                    18  => "DC2",
                    19  => "DC3",
                    20  => "DC4",
                    21  => "NAK",
                    22  => "SYN",
                    23  => "ETB",
                    24  => "CAN",
                    25  => "EM ",
                    26  => "SUB",
                    27  => "ESC",
                    28  => "FS ",
                    29  => "GS ",
                    30  => "RS ",
                    31  => "US ",
                    32  => "SPC",
                    127 => "DEL",
                    _   => "UNK",
                }
                .to_string()
            }
        }

        println!("  {}", ascii_display);

        ptr = unsafe { ptr.add(1) };
    }

    println!();
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Display the memopry content of a u16 variable.
    fn view_mem_u16(my_u16: u16) -> () {
        // Unsafe test
        view_mem!(my_u16);

        // Safe test
        safe_view_mem!(&my_u16);
    }

    /// Displays the memory content of a u64 variable.
    fn view_mem_u64(my_u64: u64) -> () {
        // Unsafe test
        view_mem!(my_u64);

        // Safe test
        safe_view_mem!(&my_u64);
    }

    /// Displays the memory content of a f32 variable.
    fn view_mem_f32(my_f32: f32) -> () {
        // Unsafe test
        view_mem!(my_f32);

        // Safe test
        safe_view_mem!(&my_f32);
    }

    /// Displays the memory content of a string variable.
    fn view_mem_str(my_str: &str) -> () {
        // Unsafe test
        view_mem!(my_str); // Print address of the first character of the my_str
        view_mem!(*my_str); // Print actual content of my_str

        // Safe test
        safe_view_mem!(&my_str);
        safe_view_mem!(my_str);
    }

    /// Displays the memory content of a pointer.
    fn view_mem_ptr<T>(my_ptr: *const T) -> () {
        // Unsafe test
        view_mem!(my_ptr);
        unsafe { view_mem!(*my_ptr); }

        // Safe test
        // Parameterized type is not supported for safe view.
    }

    /// Displays the memory content of a vector variable.
    fn view_mem_vec<T>(my_vec: Vec<T>) -> () {
        // Unsafe test
        view_mem!(my_vec);
        view_mem!(*my_vec);

        // Safe test
        // Parameterized type is not supported for safe view.
    }

    /// Displays the memory content of a boxed variable.
    fn view_mem_box<T>(my_box: Box<T>) -> () {
        // Unsafe test
        view_mem!(&my_box);
        view_mem!(my_box);
        view_mem!(*my_box);

        // Safe test
        // Parameterized type is not supported for safe view.
    }

    /// Displays the memory content of a vector of boxed variables.
    fn view_mem_vec_of_box<T>(my_vec_of_box: Vec<Box<T>>) -> () {
        // Unsafe test
        view_mem!(my_vec_of_box);
        view_mem!(*my_vec_of_box);
        view_mem!(*my_vec_of_box[0]);

        // Safe test
        // Parameterized type is not supported for safe view.
    }

    /// Displays the memory content of a struct variable.
    fn view_mem_struct<T>(my_struct: T) -> () {
        // Unsafe test
        view_mem!(&my_struct);
        view_mem!(my_struct);

        // Parameterized type is not supported for safe view.
    }
     
    struct MyStruct {
        a: u8,
        b: u16,
        c: u32,
    }

    #[derive(Serialize)]
    struct MySerializedStruct {
        a: u8,
        b: u16,
        c: u32,
    }

    #[test]
    fn u16_viewer() {
        println!("This should print the memory of the holy number 69.\n");
        assert_eq!(view_mem_u16(69), ());
    }

    fn u64_viewer() {
        println!("This should print the memory of the holy number 69.\n");
        assert_eq!(view_mem_u64(69), ());
    }

    #[test]
    fn f32_viewer() {
        println!("This should print the memory of pi in IEEE 754 representation, which is 0x4048f5c3.\n");
        assert_eq!(view_mem_f32(3.14), ());
    }

    #[test]
    fn str_viewer() {
        println!("This should print the memory of 'Hello' and its address.\n");
        assert_eq!(view_mem_str("Hello"), ());
    }

    #[test]
    fn ptr_viewer() {
        println!("This should print the memory of a pointer.\n");
        let my_ptr: *const u8 = &69;

        // Safe test
        println!("Currently pointer type is not supported by safe view memory.\n");

        // Unsafe test
        assert_eq!(view_mem_ptr(my_ptr), ());
    }

    #[test]
    fn vec_viewer() {
        println!("This should print the memory address of the vector and the memory of its elements.\n");
        let my_vec: Vec<u8> = vec![69, 255, 254, 253, 70];

        // Safe test
        safe_view_mem!(&my_vec);

        // Unsafe test
        assert_eq!(view_mem_vec(my_vec), ());
    }

    #[test]
    fn box_viewer() {
        println!("This should print the memory address of the box and the memory of its value.\n");
        let my_box: Box<u8> = Box::new(69);

        // Safe test
        safe_view_mem!(&my_box);


        // Unsafe test
        assert_eq!(view_mem_box(my_box), ());
    }

    #[test]
    fn vec_of_box_viewer() {
        println!("This should print the memory address of the vector of boxes and the memory of its elements.\n");
        let my_vec_of_box: Vec<Box<u8>> = vec![Box::new(69), Box::new(255), Box::new(254), Box::new(253), Box::new(70)];

        // Safe test
        safe_view_mem!(&my_vec_of_box);

        // Unsafe test
        assert_eq!(view_mem_vec_of_box(my_vec_of_box), ());
    }

    #[test]
    fn struct_viewer() {
        println!("This should print the memory address of the struct and the memory of its fields.\n");
        let my_struct = MyStruct {
            a: 69,
            b: 255,
            c: 70,
        };

        let my_serialized_struct = MySerializedStruct {
            a: 69,
            b: 255,
            c: 70,
        };

        // Safe test
        safe_view_mem!(&my_serialized_struct);

        // Unsafe test
        assert_eq!(view_mem_struct(my_struct), ());
    }
}