Skip to main content

rust_kernel_rt/
print.rs

1use core::fmt::{self, Write};
2
3use crate::syscall::syscall_print;
4
5struct Writer;
6
7impl fmt::Write for Writer {
8    fn write_str(&mut self, s: &str) -> fmt::Result {
9        let res = syscall_print(s);
10        if res.is_none() {
11            return Err(fmt::Error);
12        }
13        Ok(())
14    }
15}
16
17pub fn _print(args: fmt::Arguments){
18    Writer.write_fmt(args).unwrap();
19}
20
21#[macro_export]
22macro_rules! print {
23    ($($arg:tt)*) => ($crate::print::_print(format_args!($($arg)*)));
24}
25
26#[macro_export]
27macro_rules! println {
28    () => ($crate::print!("\n"));
29    ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
30}