@@ -1292,7 +1292,7 @@ impl<T> VecDeque<T> {
12921292 /// ```
12931293 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
12941294 pub fn front ( & self ) -> Option < & T > {
1295- if ! self . is_empty ( ) { Some ( & self [ 0 ] ) } else { None }
1295+ self . get ( 0 )
12961296 }
12971297
12981298 /// Provides a mutable reference to the front element, or `None` if the
@@ -1316,7 +1316,7 @@ impl<T> VecDeque<T> {
13161316 /// ```
13171317 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
13181318 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 )
13201320 }
13211321
13221322 /// Provides a reference to the back element, or `None` if the `VecDeque` is
@@ -1336,7 +1336,7 @@ impl<T> VecDeque<T> {
13361336 /// ```
13371337 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
13381338 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 ) )
13401340 }
13411341
13421342 /// Provides a mutable reference to the back element, or `None` if the
@@ -1360,8 +1360,7 @@ impl<T> VecDeque<T> {
13601360 /// ```
13611361 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
13621362 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 ) )
13651364 }
13661365
13671366 /// Removes the first element and returns it, or `None` if the `VecDeque` is
0 commit comments