Implement the fmt::Write trait and print something with the `write!` macro

master
Philipp Oppermann 8 years ago
parent 578717a9b8
commit 5e0ccd5aa5

@ -1,3 +1,4 @@
use core::fmt;
use core::ptr::Unique;
use volatile::Volatile;
@ -87,12 +88,26 @@ impl Writer {
fn new_line(&mut self) {/* TODO */}
}
impl fmt::Write for Writer {
fn write_str(&mut self, s: &str) -> fmt::Result {
for byte in s.bytes() {
self.write_byte(byte)
}
Ok(())
}
}
pub fn print_something() {
use core::fmt::Write;
let mut writer = Writer {
column_position: 0,
color_code: ColorCode::new(Color::LightGreen, Color::Black),
buffer: unsafe { Unique::new(0xb8000 as *mut _) },
};
writer.write_str("Hello!");
writer.write_byte(b'H');
writer.write_str("ello! ");
write!(writer, "The numbers are {} and {}", 42, 1.0/3.0);
}

Loading…
Cancel
Save