mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Run rustfmt
This commit is contained in:
@@ -203,9 +203,12 @@ Compiling for our new target will use Linux conventions (I'm not quite sure why,
|
|||||||
|
|
||||||
#[lang = "panic_fmt"] // define a function that should be called on panic
|
#[lang = "panic_fmt"] // define a function that should be called on panic
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_begin_panic(_msg: core::fmt::Arguments,
|
pub extern "C" fn rust_begin_panic(
|
||||||
_file: &'static str, _line: u32, _column: u32) -> !
|
_msg: core::fmt::Arguments,
|
||||||
{
|
_file: &'static str,
|
||||||
|
_line: u32,
|
||||||
|
_column: u32,
|
||||||
|
) -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,22 +71,22 @@ First, we represent the different colors using an enum:
|
|||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
Black = 0,
|
Black = 0,
|
||||||
Blue = 1,
|
Blue = 1,
|
||||||
Green = 2,
|
Green = 2,
|
||||||
Cyan = 3,
|
Cyan = 3,
|
||||||
Red = 4,
|
Red = 4,
|
||||||
Magenta = 5,
|
Magenta = 5,
|
||||||
Brown = 6,
|
Brown = 6,
|
||||||
LightGray = 7,
|
LightGray = 7,
|
||||||
DarkGray = 8,
|
DarkGray = 8,
|
||||||
LightBlue = 9,
|
LightBlue = 9,
|
||||||
LightGreen = 10,
|
LightGreen = 10,
|
||||||
LightCyan = 11,
|
LightCyan = 11,
|
||||||
LightRed = 12,
|
LightRed = 12,
|
||||||
Pink = 13,
|
Pink = 13,
|
||||||
Yellow = 14,
|
Yellow = 14,
|
||||||
White = 15,
|
White = 15,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
We use a [C-like enum] here to explicitly specify the number for each color. Because of the `repr(u8)` attribute each enum variant is stored as an `u8`. Actually 4 bits would be sufficient, but Rust doesn't have an `u4` type.
|
We use a [C-like enum] here to explicitly specify the number for each color. Because of the `repr(u8)` attribute each enum variant is stored as an `u8`. Actually 4 bits would be sufficient, but Rust doesn't have an `u4` type.
|
||||||
@@ -364,7 +364,7 @@ impl Writer {
|
|||||||
self.buffer.chars[row - 1][col].write(character);
|
self.buffer.chars[row - 1][col].write(character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.clear_row(BUFFER_HEIGHT-1);
|
self.clear_row(BUFFER_HEIGHT - 1);
|
||||||
self.column_position = 0;
|
self.column_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -3,9 +3,9 @@
|
|||||||
#![no_std] // don't link the Rust standard library
|
#![no_std] // don't link the Rust standard library
|
||||||
#![no_main] // disable all Rust-level entry points
|
#![no_main] // disable all Rust-level entry points
|
||||||
|
|
||||||
extern crate volatile;
|
|
||||||
extern crate rlibc;
|
extern crate rlibc;
|
||||||
extern crate spin;
|
extern crate spin;
|
||||||
|
extern crate volatile;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
@@ -24,9 +24,11 @@ pub extern "C" fn _start() -> ! {
|
|||||||
/// This function is called on panic.
|
/// This function is called on panic.
|
||||||
#[lang = "panic_fmt"]
|
#[lang = "panic_fmt"]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_begin_panic(_msg: core::fmt::Arguments,
|
pub extern "C" fn rust_begin_panic(
|
||||||
_file: &'static str,
|
_msg: core::fmt::Arguments,
|
||||||
_line: u32,
|
_file: &'static str,
|
||||||
_column: u32) -> ! {
|
_line: u32,
|
||||||
|
_column: u32,
|
||||||
|
) -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,22 +18,22 @@ lazy_static! {
|
|||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
Black = 0,
|
Black = 0,
|
||||||
Blue = 1,
|
Blue = 1,
|
||||||
Green = 2,
|
Green = 2,
|
||||||
Cyan = 3,
|
Cyan = 3,
|
||||||
Red = 4,
|
Red = 4,
|
||||||
Magenta = 5,
|
Magenta = 5,
|
||||||
Brown = 6,
|
Brown = 6,
|
||||||
LightGray = 7,
|
LightGray = 7,
|
||||||
DarkGray = 8,
|
DarkGray = 8,
|
||||||
LightBlue = 9,
|
LightBlue = 9,
|
||||||
LightGreen = 10,
|
LightGreen = 10,
|
||||||
LightCyan = 11,
|
LightCyan = 11,
|
||||||
LightRed = 12,
|
LightRed = 12,
|
||||||
Pink = 13,
|
Pink = 13,
|
||||||
Yellow = 14,
|
Yellow = 14,
|
||||||
White = 15,
|
White = 15,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A combination of a foreground and a background color.
|
/// A combination of a foreground and a background color.
|
||||||
@@ -119,7 +119,7 @@ impl Writer {
|
|||||||
self.buffer.chars[row - 1][col].write(character);
|
self.buffer.chars[row - 1][col].write(character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.clear_row(BUFFER_HEIGHT-1);
|
self.clear_row(BUFFER_HEIGHT - 1);
|
||||||
self.column_position = 0;
|
self.column_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user