@@ -128,16 +128,19 @@ impl RequestHandle {
128128 } ;
129129 self
130130 }
131- fn submit ( self ) -> Self {
132- match self {
133- Self :: Init ( handle) => Self :: Pending ( handle. submit ( ) ) ,
131+
132+ // This method can modify in-place instead of returning a new value. This removes the need for
133+ // a RefCell in V4l2Request.
134+ fn submit ( & mut self ) {
135+ match std:: mem:: take ( self ) {
136+ Self :: Init ( handle) => * self = Self :: Pending ( handle. submit ( ) ) ,
134137 _ => panic ! ( "ERROR" ) ,
135138 }
136139 }
137- fn sync ( self ) -> Self {
138- match self {
139- Self :: Pending ( handle) => Self :: Done ( handle. sync ( ) ) ,
140- Self :: Done ( _) => self ,
140+ fn sync ( & mut self ) {
141+ match std :: mem :: take ( self ) {
142+ Self :: Pending ( handle) => * self = Self :: Done ( handle. sync ( ) ) ,
143+ s @ Self :: Done ( _) => * self = s ,
141144 _ => panic ! ( "ERROR" ) ,
142145 }
143146 }
@@ -149,9 +152,7 @@ impl RequestHandle {
149152 }
150153}
151154
152- pub struct V4l2Request {
153- handle : RefCell < RequestHandle > ,
154- }
155+ pub struct V4l2Request ( RequestHandle ) ;
155156
156157impl V4l2Request {
157158 pub fn new (
@@ -160,35 +161,31 @@ impl V4l2Request {
160161 handle : ioctl:: Request ,
161162 buffer : V4l2OutputBuffer ,
162163 ) -> Self {
163- Self {
164- handle : RefCell :: new ( RequestHandle :: new ( device, timestamp, handle, buffer) ) ,
165- }
164+ Self ( RequestHandle :: new ( device, timestamp, handle, buffer) )
166165 }
167166 pub fn timestamp ( & self ) -> u64 {
168- self . handle . borrow ( ) . timestamp ( )
167+ self . 0 . timestamp ( )
169168 }
170- pub fn ioctl < C , T > ( & self , ctrl : C ) -> & Self
169+ pub fn ioctl < C , T > ( & mut self , ctrl : C ) -> & mut Self
171170 where
172171 C : Into < SafeExtControl < T > > ,
173172 T : ExtControlTrait ,
174173 {
175- self . handle . borrow_mut ( ) . ioctl ( ctrl) ;
174+ self . 0 . ioctl ( ctrl) ;
176175 self
177176 }
178- pub fn write ( & self , data : & [ u8 ] ) -> & Self {
179- self . handle . borrow_mut ( ) . write ( data) ;
177+ pub fn write ( & mut self , data : & [ u8 ] ) -> & mut Self {
178+ self . 0 . write ( data) ;
180179 self
181180 }
182- pub fn submit ( & self ) -> & Self {
183- self . handle . replace ( self . handle . take ( ) . submit ( ) ) ;
184- self
181+ pub fn submit ( & mut self ) {
182+ self . 0 . submit ( ) ;
185183 }
186- pub fn sync ( & self ) -> & Self {
187- self . handle . replace ( self . handle . take ( ) . sync ( ) ) ;
188- self
184+ pub fn sync ( & mut self ) {
185+ self . 0 . sync ( ) ;
189186 }
190187 pub fn result ( & self ) -> V4l2Result {
191- self . handle . borrow ( ) . result ( )
188+ self . 0 . result ( )
192189 }
193190}
194191
0 commit comments