Skip to content

Commit f129d7a

Browse files
bors[bot]burrbull
andcommitted
Merge #354
354: add variant to reader r=therealprof a=burrbull r? @therealprof Restore access to `enum`'s by `variant` method that return `enum FIELD` when possible or `Variant`. Also replace `_to_bits` method in writer with trait. So now enums for reader and writer are identical (when they don't use different values for read and write) and can be replaced by one. See #353 . Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents ce0a47c + e7d448e commit f129d7a

File tree

3 files changed

+172
-157
lines changed

3 files changed

+172
-157
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `variant()` method for field reader and `Variant` enum for fields with reserved values
13+
1014
## [v0.15.2] - 2019-07-29
1115

1216
- No changes, just fixing the metadata since crates.io didn't like the keywords

src/generate/generic.rs

+11
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ pub fn render() -> Result<Vec<Tokens>> {
7474
}
7575
});
7676

77+
generic_items.push(quote! {
78+
///Used if enumerated values cover not the whole range
79+
#[derive(Clone,Copy,PartialEq)]
80+
pub enum Variant<U, T> {
81+
///Expected variant
82+
Val(T),
83+
///Raw bits
84+
Res(U),
85+
}
86+
});
87+
7788
code.push(quote! {
7889
#[allow(unused_imports)]
7990
use generic::*;

0 commit comments

Comments
 (0)