From 4db15a7e80a76f54ea7f76f53ac3535a5c179dcd Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 27 Sep 2016 13:25:03 +0200 Subject: [PATCH] Update post to new bit_field code --- blog/post/09-catching-exceptions.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blog/post/09-catching-exceptions.md b/blog/post/09-catching-exceptions.md index 11d70757..40ee25fe 100644 --- a/blog/post/09-catching-exceptions.md +++ b/blog/post/09-catching-exceptions.md @@ -146,7 +146,7 @@ Or: self.0 = ((self.0 >> 3) << 3) | stack_index; ``` -Well, none of these variants is really _readable_ and it's very easy to make mistakes somewhere. Therefore I created a `BitField` type with the following [Range]-based API: +Well, none of these variants is really _readable_ and it's very easy to make mistakes somewhere. Therefore I created a `BitField` trait that provides the following [Range]-based API: [Range]: https://doc.rust-lang.org/nightly/core/ops/struct.Range.html @@ -154,11 +154,11 @@ Well, none of these variants is really _readable_ and it's very easy to make mis self.0.set_range(0..3, stack_index); ``` -I think it is much more readable, since we abstracted away all bit-masking details. The `BitField` type is contained in the [bit_field] crate. (It's pretty new, so it might still contain bugs.) To add it as dependency, we run `cargo add bit_field` and add `extern crate bit_field;` to our `src/lib.rs`. +I think it is much more readable, since we abstracted away all bit-masking details. The `BitField` trait is contained in the [bit_field] crate. (It's pretty new, so it might still contain bugs.) To add it as dependency, we run `cargo add bit_field` and add `extern crate bit_field;` to our `src/lib.rs`. [bit_field]: https://crates.io/crates/bit_field -Now we can use the crate to implement the methods of `EntryOptions`: +Now we can use the trait to implement the methods of `EntryOptions`: ```rust // in src/interrupts/idt.rs @@ -166,11 +166,11 @@ Now we can use the crate to implement the methods of `EntryOptions`: use bit_field::BitField; #[derive(Debug, Clone, Copy)] -pub struct EntryOptions(BitField); +pub struct EntryOptions(u16); impl EntryOptions { fn minimal() -> Self { - let mut options = BitField::new(0); + let mut options = 0; options.set_range(9..12, 0b111); // 'must-be-one' bits EntryOptions(options) }