mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-26 03:13:36 +04:00
32 lines
675 B
Rust
32 lines
675 B
Rust
use crate::drivers::chardev::{CharDevice, UART};
|
|
use core::fmt::{self, Write};
|
|
|
|
struct Stdout;
|
|
|
|
impl Write for Stdout {
|
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
for c in s.chars() {
|
|
UART.write(c as u8);
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub fn print(args: fmt::Arguments) {
|
|
Stdout.write_fmt(args).unwrap();
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! print {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!($fmt $(, $($arg)+)?))
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! println {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?))
|
|
}
|
|
}
|