mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-02-09 21:25:59 +08:00
38 lines
725 B
Rust
38 lines
725 B
Rust
/*!
|
||
|
||
本模块实现了 print 和 println 宏。
|
||
|
||
*/
|
||
|
||
use crate::sbi::console_putchar;
|
||
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() {
|
||
console_putchar(c as usize);
|
||
}
|
||
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)+)?));
|
||
}
|
||
}
|