Skip to content

Commit 97b4738

Browse files
bors[bot]qwandor
andauthored
Merge #3013
3013: tock-register-interface: Provide `none` method for FieldValue type. r=lschuermann a=qwandor ### Pull Request Overview `Default` is useful to construct a `FieldValue` which can be passed to `modify` as a no-op or used as an additive identity when combining other `FieldValue`s. `Eq` and `PartialEq` are useful for assertions in testing. ### Testing Strategy This pull request was tested by `cargo test`. ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Andrew Walbran <[email protected]>
2 parents 0281b23 + 0d6db7d commit 97b4738

File tree

1 file changed

+10
-0
lines changed
  • libraries/tock-register-interface/src

1 file changed

+10
-0
lines changed

libraries/tock-register-interface/src/fields.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ FieldValue_impl_for!(u128);
230230
FieldValue_impl_for!(usize);
231231

232232
impl<T: UIntLike, R: RegisterLongName> FieldValue<T, R> {
233+
#[inline]
234+
pub fn none() -> Self {
235+
Self {
236+
mask: T::zero(),
237+
value: T::zero(),
238+
associated_register: PhantomData,
239+
}
240+
}
241+
233242
/// Get the raw bitmask represented by this FieldValue.
234243
#[inline]
235244
pub fn mask(&self) -> T {
@@ -390,6 +399,7 @@ macro_rules! register_bitmasks {
390399

391400
#[allow(dead_code)]
392401
#[allow(non_camel_case_types)]
402+
#[derive(Copy, Clone, Eq, PartialEq)]
393403
#[repr($valtype)] // so that values larger than isize::MAX can be stored
394404
$(#[$outer])*
395405
pub enum Value {

0 commit comments

Comments
 (0)