Skip to content

Commit 294e211

Browse files
committed
Revert "arbitrary return type for register modifiers"
This reverts commit 456ce21.
1 parent 36fe955 commit 294e211

File tree

1 file changed

+35
-43
lines changed

1 file changed

+35
-43
lines changed

src/generate/generic_reg_vcell.rs

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,18 @@ impl<REG: Resettable + Writable> Reg<REG> {
7474
/// ```
7575
/// In the latter case, other fields will be set to their reset value.
7676
#[inline(always)]
77-
pub fn write<F, T>(&self, f: F) -> T
77+
pub fn write<F>(&self, f: F)
7878
where
79-
F: FnOnce(&mut W<REG>) -> T,
79+
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
8080
{
81-
let mut writer = W {
82-
bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
83-
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
84-
_reg: marker::PhantomData,
85-
};
86-
let result = f(&mut writer);
87-
88-
self.register.set(writer.bits);
89-
90-
result
81+
self.register.set(
82+
f(&mut W {
83+
bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
84+
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
85+
_reg: marker::PhantomData,
86+
})
87+
.bits,
88+
);
9189
}
9290
}
9391

@@ -100,20 +98,17 @@ impl<REG: Writable> Reg<REG> {
10098
///
10199
/// Unsafe to use with registers which don't allow to write 0.
102100
#[inline(always)]
103-
pub unsafe fn write_with_zero<F, T>(&self, f: F) -> T
101+
pub unsafe fn write_with_zero<F>(&self, f: F)
104102
where
105-
F: FnOnce(&mut W<REG>) -> T,
103+
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
106104
{
107-
let mut writer = W {
108-
bits: REG::Ux::default(),
109-
_reg: marker::PhantomData,
110-
};
111-
112-
let result = f(&mut writer);
113-
114-
self.register.set(writer.bits);
115-
116-
result
105+
self.register.set(
106+
f(&mut W {
107+
bits: REG::Ux::default(),
108+
_reg: marker::PhantomData,
109+
})
110+
.bits,
111+
);
117112
}
118113
}
119114

@@ -144,34 +139,31 @@ impl<REG: Readable + Writable> Reg<REG> {
144139
/// ```
145140
/// Other fields will have the value they had before the call to `modify`.
146141
#[inline(always)]
147-
pub fn modify<F, T>(&self, f: F) -> T
142+
pub fn modify<F>(&self, f: F)
148143
where
149-
for<'w> F: FnOnce(&R<REG>, &'w mut W<REG>) -> T,
144+
for<'w> F: FnOnce(&R<REG>, &'w mut W<REG>) -> &'w mut W<REG>,
150145
{
151146
let bits = self.register.get();
152-
153-
let mut writer = W {
154-
bits: bits & !REG::ONE_TO_MODIFY_FIELDS_BITMAP | REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
155-
_reg: marker::PhantomData,
156-
};
157-
158-
let result = f(
159-
&R {
160-
bits,
161-
_reg: marker::PhantomData,
162-
},
163-
&mut writer,
147+
self.register.set(
148+
f(
149+
&R {
150+
bits,
151+
_reg: marker::PhantomData,
152+
},
153+
&mut W {
154+
bits: bits & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
155+
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
156+
_reg: marker::PhantomData,
157+
},
158+
)
159+
.bits,
164160
);
165-
166-
self.register.set(writer.bits);
167-
168-
result
169161
}
170162
}
171163

172164
impl<REG: Readable> core::fmt::Debug for crate::generic::Reg<REG>
173165
where
174-
R<REG>: core::fmt::Debug,
166+
R<REG>: core::fmt::Debug
175167
{
176168
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
177169
core::fmt::Debug::fmt(&self.read(), f)

0 commit comments

Comments
 (0)