1use crate::structs::*;
2use crate::vmapi;
3use crate::name::{ Name };
4
5pub fn prints(s: &str) {
7 vmapi::print::prints_l(s.as_bytes().as_ptr(), s.len() as u32);
8}
9
10pub fn printi(value: i64) {
12 vmapi::print::printi(value);
13}
14
15pub fn printui(value: u64) {
17 vmapi::print::printui(value);
18}
19
20pub fn printi128(value: i128) {
22 vmapi::print::printi128(value);
23}
24
25pub fn printui128(value: u128) {
27 vmapi::print::printui128(value);
28}
29
30pub fn printsf(value: f32) {
32 vmapi::print::printsf(value);
33}
34
35pub fn printdf(value: f64) {
37 vmapi::print::printdf(value);
38}
39
40pub fn printqf(value: &Float128) {
42 vmapi::print::printqf(value);
43}
44
45pub fn printn(name: Name) {
47 vmapi::print::printn(name.value());
48}
49
50pub fn printhex(data: &[u8]) {
52 vmapi::print::printhex(data.as_ptr(), data.len() as u32);
53}
54
55pub trait Printable {
57 fn print(&self);
59}
60
61impl Printable for Name {
62 fn print(&self) {
64 printn(*self);
65 }
66}
67
68impl Printable for bool {
69 fn print(&self) {
71 if *self {
72 prints("true");
73 } else {
74 prints("false");
75 }
76 }
77}
78
79impl Printable for i8 {
80 fn print(&self) {
82 printi(*self as i64);
83 }
84}
85
86impl Printable for u8 {
87 fn print(&self) {
89 printi(*self as i64);
90 }
91}
92
93impl Printable for i16 {
94 fn print(&self) {
96 printi(*self as i64);
97 }
98}
99
100impl Printable for u16 {
101 fn print(&self) {
103 printi(*self as i64);
104 }
105}
106
107impl Printable for i32 {
108 fn print(&self) {
110 printi(*self as i64);
111 }
112}
113
114impl Printable for u32 {
115 fn print(&self) {
117 printui(*self as u64);
118 }
119}
120
121impl Printable for usize {
122 fn print(&self) {
124 printui(*self as u64);
125 }
126}
127
128impl Printable for i64 {
129 fn print(&self) {
131 printi(*self);
132 }
133}
134
135impl Printable for u64 {
136 fn print(&self) {
138 printui(*self);
139 }
140}
141
142impl Printable for i128 {
143 fn print(&self) {
145 printi128(*self);
146 }
147}
148
149impl Printable for u128 {
150 fn print(&self) {
152 printui128(*self);
153 }
154}
155
156impl Printable for [u8] {
157 fn print(&self) {
159 printhex(self);
160 }
161}
162
163impl Printable for str {
164 fn print(&self) {
166 prints(self);
167 }
168}
169
170impl Printable for f32 {
171 fn print(&self) {
173 printsf(*self);
174 }
175}
176
177impl Printable for f64 {
178 fn print(&self) {
180 printdf(*self);
181 }
182}
183
184impl Printable for Float128 {
185 fn print(&self) {
187 printqf(self);
188 }
189}
190
191#[macro_export]
205macro_rules! eosio_print {
206 ($last:expr) => {
207 $last.print();
208 };
209 ($head:expr, $($tail:expr), +) => {
210 $head.print();
211 $crate::print::prints(" ");
212 eosio_print!($($tail),+);
213 };
214}
215
216#[macro_export]
218macro_rules! chain_println {
219 ( $last:expr ) => {
220 $last.print();
221 $crate::print::prints("\n");
222 };
223 ( $head:expr, $($tail:expr), + ) => {
224 $head.print();
225 $crate::print::prints(" ");
226 chain_println!($($tail),+);
227 };
228}