Update posts to latest bit_field version

This commit is contained in:
Philipp Oppermann
2017-01-25 13:46:21 +01:00
parent 46100ba24b
commit 8b807a7d25
2 changed files with 10 additions and 10 deletions

View File

@@ -148,7 +148,7 @@ Well, none of these variants is really _readable_ and it's very easy to make mis
[Range]: https://doc.rust-lang.org/nightly/core/ops/struct.Range.html
``` rust
self.0.set_range(0..3, stack_index);
self.0.set_bits(0..3, stack_index);
```
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`.
@@ -168,7 +168,7 @@ pub struct EntryOptions(u16);
impl EntryOptions {
fn minimal() -> Self {
let mut options = 0;
options.set_range(9..12, 0b111); // 'must-be-one' bits
options.set_bits(9..12, 0b111); // 'must-be-one' bits
EntryOptions(options)
}
@@ -189,12 +189,12 @@ impl EntryOptions {
}
pub fn set_privilege_level(&mut self, dpl: u16) -> &mut Self {
self.0.set_range(13..15, dpl);
self.0.set_bits(13..15, dpl);
self
}
pub fn set_stack_index(&mut self, index: u16) -> &mut Self {
self.0.set_range(0..3, index);
self.0.set_bits(0..3, index);
self
}
}