mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Implement support for Rust's formatting macros
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use core::fmt;
|
||||
use volatile::Volatile;
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -88,7 +89,15 @@ impl Writer {
|
||||
fn new_line(&mut self) {/* TODO */}
|
||||
}
|
||||
|
||||
impl fmt::Write for Writer {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
self.write_string(s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_something() {
|
||||
use core::fmt::Write;
|
||||
let mut writer = Writer {
|
||||
column_position: 0,
|
||||
color_code: ColorCode::new(Color::Yellow, Color::Black),
|
||||
@@ -96,6 +105,6 @@ pub fn print_something() {
|
||||
};
|
||||
|
||||
writer.write_byte(b'H');
|
||||
writer.write_string("ello ");
|
||||
writer.write_string("Wörld!");
|
||||
writer.write_string("ello! ");
|
||||
write!(writer, "The numbers are {} and {}", 42, 1.0 / 3.0).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user