@@ -74,20 +74,18 @@ impl<REG: Resettable + Writable> Reg<REG> {
74
74
/// ```
75
75
/// In the latter case, other fields will be set to their reset value.
76
76
#[ inline( always) ]
77
- pub fn write < F , T > ( & self , f : F ) -> T
77
+ pub fn write < F > ( & self , f : F )
78
78
where
79
- F : FnOnce ( & mut W < REG > ) -> T ,
79
+ F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
80
80
{
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
+ ) ;
91
89
}
92
90
}
93
91
@@ -100,20 +98,17 @@ impl<REG: Writable> Reg<REG> {
100
98
///
101
99
/// Unsafe to use with registers which don't allow to write 0.
102
100
#[ 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 )
104
102
where
105
- F : FnOnce ( & mut W < REG > ) -> T ,
103
+ F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
106
104
{
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
+ ) ;
117
112
}
118
113
}
119
114
@@ -144,34 +139,31 @@ impl<REG: Readable + Writable> Reg<REG> {
144
139
/// ```
145
140
/// Other fields will have the value they had before the call to `modify`.
146
141
#[ inline( always) ]
147
- pub fn modify < F , T > ( & self , f : F ) -> T
142
+ pub fn modify < F > ( & self , f : F )
148
143
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 > ,
150
145
{
151
146
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 ,
164
160
) ;
165
-
166
- self . register . set ( writer. bits ) ;
167
-
168
- result
169
161
}
170
162
}
171
163
172
164
impl < REG : Readable > core:: fmt:: Debug for crate :: generic:: Reg < REG >
173
165
where
174
- R < REG > : core:: fmt:: Debug ,
166
+ R < REG > : core:: fmt:: Debug
175
167
{
176
168
fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
177
169
core:: fmt:: Debug :: fmt ( & self . read ( ) , f)
0 commit comments