@@ -291,6 +291,13 @@ impl<T, const N: usize> Vec<T, N> {
291
291
{
292
292
self . as_mut_view ( ) . drain ( range)
293
293
}
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
+ }
294
301
}
295
302
296
303
impl < T > VecView < T > {
@@ -408,7 +415,7 @@ impl<T, S: Storage> VecInner<T, S> {
408
415
}
409
416
410
417
/// Returns the maximum number of elements the vector can hold.
411
- pub fn capacity ( & self ) -> usize {
418
+ pub fn storage_capacity ( & self ) -> usize {
412
419
self . buffer . borrow ( ) . len ( )
413
420
}
414
421
@@ -487,7 +494,7 @@ impl<T, S: Storage> VecInner<T, S> {
487
494
///
488
495
/// Returns back the `item` if the vector is full.
489
496
pub fn push ( & mut self , item : T ) -> Result < ( ) , T > {
490
- if self . len < self . capacity ( ) {
497
+ if self . len < self . storage_capacity ( ) {
491
498
unsafe { self . push_unchecked ( item) }
492
499
Ok ( ( ) )
493
500
} else {
@@ -561,7 +568,7 @@ impl<T, S: Storage> VecInner<T, S> {
561
568
where
562
569
T : Clone ,
563
570
{
564
- if new_len > self . capacity ( ) {
571
+ if new_len > self . storage_capacity ( ) {
565
572
return Err ( ( ) ) ;
566
573
}
567
574
@@ -681,7 +688,7 @@ impl<T, S: Storage> VecInner<T, S> {
681
688
/// Normally, here, one would use [`clear`] instead to correctly drop
682
689
/// the contents and thus not leak memory.
683
690
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 ( ) ) ;
685
692
686
693
self . len = new_len
687
694
}
@@ -757,7 +764,7 @@ impl<T, S: Storage> VecInner<T, S> {
757
764
758
765
/// Returns true if the vec is full
759
766
pub fn is_full ( & self ) -> bool {
760
- self . len == self . capacity ( )
767
+ self . len == self . storage_capacity ( )
761
768
}
762
769
763
770
/// Returns true if the vec is empty
0 commit comments