From 4a1fa3a65ae8e77988b7c5a01b9360e585b1c29d Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 4 Aug 2016 20:06:56 +0200 Subject: [PATCH] Explain how to add lazy_static to the main crate --- blog/post/2016-05-28-catching-exceptions.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/blog/post/2016-05-28-catching-exceptions.md b/blog/post/2016-05-28-catching-exceptions.md index e9dfd3ae..11d70757 100644 --- a/blog/post/2016-05-28-catching-exceptions.md +++ b/blog/post/2016-05-28-catching-exceptions.md @@ -435,6 +435,24 @@ The reason is that the Rust compiler is not able to evaluate the value of the `s #### Lazy Statics to the Rescue Fortunately the `lazy_static` macro exists. Instead of evaluating a `static` at compile time, the macro performs the initialization when the `static` is referenced the first time. Thus, we can do almost everything in the initialization block and are even able to read runtime values. +Let's add the `lazy_static` crate to our project: + +```rust +// in src/lib.rs + +#[macro_use] +extern crate lazy_static; +``` + +```toml +# in Cargo.toml + +[dependencies.lazy_static] +version = "0.2.1" +features = ["spin_no_std"] +``` +We need the `spin_no_std` feature, since we don't link the standard library. + With `lazy_static`, we can define our IDT without problems: ```rust