Import lazy_static through normal use

This commit is contained in:
Philipp Oppermann
2018-11-13 11:36:40 +01:00
parent 21f3152dc0
commit e7d4012653
9 changed files with 11 additions and 4 deletions

View File

@@ -478,7 +478,6 @@ Let's add the `lazy_static` crate to our project:
```rust
// in src/main.rs
#[macro_use]
extern crate lazy_static;
```
@@ -490,13 +489,15 @@ version = "1.0"
features = ["spin_no_std"]
```
We need the `spin_no_std` feature, since we don't link the standard library. We also need the `#[macro_use]` attribute on the `extern crate` line to import the `lazy_static!` macro.
We need the `spin_no_std` feature, since we don't link the standard library.
With `lazy_static`, we can define our static `WRITER` without problems:
```rust
// in src/vga_buffer.rs
use lazy_static::lazy_static;
lazy_static! {
pub static ref WRITER: Writer = Writer {
column_position: 0,

View File

@@ -85,6 +85,7 @@ mod serial;
use uart_16550::SerialPort;
use spin::Mutex;
use lazy_static::lazy_static;
lazy_static! {
pub static ref SERIAL1: Mutex<SerialPort> = {
@@ -375,7 +376,6 @@ Cargo supports hybrid projects that are both a library and a binary. We only nee
extern crate bootloader;
extern crate spin;
extern crate volatile;
#[macro_use]
extern crate lazy_static;
extern crate uart_16550;
extern crate x86_64;

View File

@@ -382,6 +382,8 @@ We already imported the `lazy_static` crate when we [created an abstraction for
```rust
// in src/interrupts.rs
use lazy_static::lazy_static;
lazy_static! {
static ref IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();

View File

@@ -235,6 +235,7 @@ pub mod gdt;
use x86_64::VirtAddr;
use x86_64::structures::tss::TaskStateSegment;
use lazy_static::lazy_static;
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;

View File

@@ -1,6 +1,7 @@
use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector};
use x86_64::structures::tss::TaskStateSegment;
use x86_64::VirtAddr;
use lazy_static::lazy_static;
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;

View File

@@ -8,6 +8,7 @@ use gdt;
use pic8259_simple::ChainedPics;
use spin;
use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable};
use lazy_static::lazy_static;
pub const PIC_1_OFFSET: u8 = 32;
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;

View File

@@ -4,7 +4,6 @@
extern crate bootloader;
extern crate spin;
extern crate volatile;
#[macro_use]
extern crate lazy_static;
extern crate pic8259_simple;
extern crate uart_16550;

View File

@@ -1,5 +1,6 @@
use spin::Mutex;
use uart_16550::SerialPort;
use lazy_static::lazy_static;
lazy_static! {
pub static ref SERIAL1: Mutex<SerialPort> = {

View File

@@ -1,6 +1,7 @@
use core::fmt;
use spin::Mutex;
use volatile::Volatile;
use lazy_static::lazy_static;
lazy_static! {
/// A global `Writer` instance that can be used for printing to the VGA text buffer.