Clarify documentation

This commit is contained in:
Julien Cretin
2020-09-29 19:29:06 +02:00
parent fa66a613f3
commit abe1230364

View File

@@ -24,7 +24,7 @@ use crate::{StoreError, StoreResult};
/// ///
/// # Invariant /// # Invariant
/// ///
/// - `pos + len < 32`. /// - The bit field must fit in a 32-bits word: `pos + len < 32`.
pub struct Field { pub struct Field {
/// The position of the bit field. /// The position of the bit field.
pub pos: usize, pub pos: usize,
@@ -43,8 +43,8 @@ impl Field {
/// ///
/// # Preconditions /// # Preconditions
/// ///
/// - `num_bits(value) < self.len`. /// - The value must fit in the bit field: `num_bits(value) < self.len`.
/// - `self.get(*word) & value == value`. /// - The value must only change bits from 1 to 0: `self.get(*word) & value == value`.
pub fn set(&self, word: &mut u32, value: usize) { pub fn set(&self, word: &mut u32, value: usize) {
let value = value as u32; let value = value as u32;
debug_assert_eq!(value & self.mask(), value); debug_assert_eq!(value & self.mask(), value);
@@ -54,6 +54,9 @@ impl Field {
} }
/// Returns a bit mask the length of the bit field. /// Returns a bit mask the length of the bit field.
///
/// The mask is meant to be applied on a value. It should be shifted to be applied to the bit
/// field.
fn mask(&self) -> u32 { fn mask(&self) -> u32 {
(1 << self.len) - 1 (1 << self.len) - 1
} }
@@ -63,7 +66,7 @@ impl Field {
/// ///
/// # Invariant /// # Invariant
/// ///
/// - `num_bits(value) <= field.len`. /// - The value must fit in the bit field: `num_bits(value) <= field.len`.
pub struct Const { pub struct Const {
/// The bit field. /// The bit field.
pub field: Field, pub field: Field,
@@ -88,7 +91,7 @@ impl Const {
/// ///
/// # Invariant /// # Invariant
/// ///
/// - `pos < 32`. /// - The bit must fit in a 32-bits word: `pos < 32`.
pub struct Bit { pub struct Bit {
/// The position of the bit. /// The position of the bit.
pub pos: usize, pub pos: usize,