@@ -291,6 +291,13 @@ impl<T, const N: usize> Vec<T, N> {
291291 {
292292 self . as_mut_view ( ) . drain ( range)
293293 }
294+
295+ /// Returns the maximum number of elements the vector can hold.
296+ ///
297+ /// This method is not available on a `VecView`, use [`storage_len`](VecInner::storage_capacity) instead
298+ pub const fn capacity ( & self ) -> usize {
299+ self . buffer . len ( )
300+ }
294301}
295302
296303impl < T > VecView < T > {
@@ -408,7 +415,7 @@ impl<T, S: Storage> VecInner<T, S> {
408415 }
409416
410417 /// Returns the maximum number of elements the vector can hold.
411- pub fn capacity ( & self ) -> usize {
418+ pub fn storage_capacity ( & self ) -> usize {
412419 self . buffer . borrow ( ) . len ( )
413420 }
414421
@@ -487,7 +494,7 @@ impl<T, S: Storage> VecInner<T, S> {
487494 ///
488495 /// Returns back the `item` if the vector is full.
489496 pub fn push ( & mut self , item : T ) -> Result < ( ) , T > {
490- if self . len < self . capacity ( ) {
497+ if self . len < self . storage_capacity ( ) {
491498 unsafe { self . push_unchecked ( item) }
492499 Ok ( ( ) )
493500 } else {
@@ -561,7 +568,7 @@ impl<T, S: Storage> VecInner<T, S> {
561568 where
562569 T : Clone ,
563570 {
564- if new_len > self . capacity ( ) {
571+ if new_len > self . storage_capacity ( ) {
565572 return Err ( ( ) ) ;
566573 }
567574
@@ -681,7 +688,7 @@ impl<T, S: Storage> VecInner<T, S> {
681688 /// Normally, here, one would use [`clear`] instead to correctly drop
682689 /// the contents and thus not leak memory.
683690 pub unsafe fn set_len ( & mut self , new_len : usize ) {
684- debug_assert ! ( new_len <= self . capacity ( ) ) ;
691+ debug_assert ! ( new_len <= self . storage_capacity ( ) ) ;
685692
686693 self . len = new_len
687694 }
@@ -757,7 +764,7 @@ impl<T, S: Storage> VecInner<T, S> {
757764
758765 /// Returns true if the vec is full
759766 pub fn is_full ( & self ) -> bool {
760- self . len == self . capacity ( )
767+ self . len == self . storage_capacity ( )
761768 }
762769
763770 /// Returns true if the vec is empty
0 commit comments