@@ -1292,7 +1292,7 @@ impl<T> VecDeque<T> {
1292
1292
/// ```
1293
1293
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1294
1294
pub fn front ( & self ) -> Option < & T > {
1295
- if ! self . is_empty ( ) { Some ( & self [ 0 ] ) } else { None }
1295
+ self . get ( 0 )
1296
1296
}
1297
1297
1298
1298
/// Provides a mutable reference to the front element, or `None` if the
@@ -1316,7 +1316,7 @@ impl<T> VecDeque<T> {
1316
1316
/// ```
1317
1317
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1318
1318
pub fn front_mut ( & mut self ) -> Option < & mut T > {
1319
- if ! self . is_empty ( ) { Some ( & mut self [ 0 ] ) } else { None }
1319
+ self . get_mut ( 0 )
1320
1320
}
1321
1321
1322
1322
/// Provides a reference to the back element, or `None` if the `VecDeque` is
@@ -1336,7 +1336,7 @@ impl<T> VecDeque<T> {
1336
1336
/// ```
1337
1337
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1338
1338
pub fn back ( & self ) -> Option < & T > {
1339
- if ! self . is_empty ( ) { Some ( & self [ self . len ( ) - 1 ] ) } else { None }
1339
+ self . get ( self . len ( ) . wrapping_sub ( 1 ) )
1340
1340
}
1341
1341
1342
1342
/// Provides a mutable reference to the back element, or `None` if the
@@ -1360,8 +1360,7 @@ impl<T> VecDeque<T> {
1360
1360
/// ```
1361
1361
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1362
1362
pub fn back_mut ( & mut self ) -> Option < & mut T > {
1363
- let len = self . len ( ) ;
1364
- if !self . is_empty ( ) { Some ( & mut self [ len - 1 ] ) } else { None }
1363
+ self . get_mut ( self . len ( ) . wrapping_sub ( 1 ) )
1365
1364
}
1366
1365
1367
1366
/// Removes the first element and returns it, or `None` if the `VecDeque` is
0 commit comments