Skip to content

Commit e980af9

Browse files
committed
use Option<ENUM> instead of Variant
1 parent a93762e commit e980af9

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2828

2929
### Changed
3030

31+
- [breaking-change] remove `Variant<U, ENUM_A>`, use `Option<ENUM_A>` instead
32+
3133
- split out register size type (`RawType`) from `ResetValue` trait
3234

3335
- `anyhow` crate is used for error handling

src/generate/generic.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,6 @@ impl<REG: RegisterSpec> W<REG> {
223223
}
224224
}
225225

226-
/// Used if enumerated values cover not the whole range.
227-
#[derive(Clone, Copy, PartialEq)]
228-
pub enum Variant<U, T> {
229-
/// Expected variant.
230-
Val(T),
231-
/// Raw bits.
232-
Res(U),
233-
}
234-
235226
/// Field reader.
236227
///
237228
/// Result of the `read` methods of fields.

src/generate/register.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ pub fn fields(
451451
let pc = &v.pc;
452452

453453
if has_reserved_variant {
454-
quote! { #i => Val(#name_pc_a::#pc), }
454+
quote! { #i => Some(#name_pc_a::#pc), }
455455
} else {
456456
quote! { #i => #name_pc_a::#pc, }
457457
}
@@ -461,7 +461,7 @@ pub fn fields(
461461

462462
if has_reserved_variant {
463463
arms.extend(quote! {
464-
i => Res(i),
464+
_ => None,
465465
});
466466
} else if 1 << width.to_ty_width()? != variants.len() {
467467
arms.extend(quote! {
@@ -473,8 +473,7 @@ pub fn fields(
473473
enum_items.extend(quote! {
474474
///Get enumerated values variant
475475
#inline
476-
pub fn variant(&self) -> crate::Variant<#fty, #name_pc_a> {
477-
use crate::Variant::*;
476+
pub fn variant(&self) -> Option<#name_pc_a> {
478477
match self.bits {
479478
#arms
480479
}

0 commit comments

Comments
 (0)