4646#![ deny( unsafe_op_in_unsafe_fn) ]
4747
4848extern crate alloc;
49+ mod collect;
4950mod set_len_on_drop;
5051
52+ use alloc:: {
53+ collections:: { TryReserveError , TryReserveErrorKind } ,
54+ vec:: Vec ,
55+ } ;
5156use core:: {
5257 alloc:: Allocator ,
5358 ops:: { Range , RangeBounds } ,
5459 slice,
5560} ;
56-
57- use alloc:: {
58- collections:: { TryReserveError , TryReserveErrorKind } ,
59- vec:: Vec ,
60- } ;
6161use set_len_on_drop:: SetLenOnDrop ;
6262
63+ pub use collect:: TryCollect ;
64+
6365// These are defined so that the try_vec! and try_vec_in! macros can refer to
6466// these types in a consistent way: even if the consuming crate doesn't use
6567// `no_std` and `extern crate alloc`.
@@ -68,7 +70,7 @@ pub mod alloc_usings {
6870 pub use alloc:: { alloc:: Layout , boxed:: Box , collections:: TryReserveError , vec:: Vec } ;
6971}
7072
71- /// Methods available for all `Vec` instantiations .
73+ /// Fallible allocation methods for [ `Vec`] .
7274pub trait FallibleVec < T , A : Allocator > : Sized {
7375 /// Extends the `Vec` using the items from the given iterator.
7476 ///
@@ -430,7 +432,7 @@ impl<T, A: Allocator> FallibleVec<T, A> for Vec<T, A> {
430432 }
431433
432434 // Gather up the remainder and copy those as well.
433- let remainder = try_collect_in ( replace_with , alloc) ?;
435+ let remainder = replace_with . try_collect_in ( alloc) ?;
434436 if !remainder. is_empty ( ) {
435437 move_tail ( self , index, remainder. len ( ) ) ?;
436438 // Don't need to use `SetLenOnDrop` here since we're enumerating
@@ -670,24 +672,6 @@ pub fn try_with_capacity<T>(size: usize) -> Result<Vec<T>, TryReserveError> {
670672 Ok ( vec)
671673}
672674
673- /// Attempts to collect items from an iterator into a vector with the provided
674- /// allocator.
675- pub fn try_collect_in < T , A : Allocator > (
676- iter : impl Iterator < Item = T > ,
677- alloc : A ,
678- ) -> Result < Vec < T , A > , TryReserveError > {
679- let mut vec = Vec :: new_in ( alloc) ;
680- vec. try_extend ( iter) ?;
681- Ok ( vec)
682- }
683-
684- /// Attempts to collect items from an iterator into a vector.
685- pub fn try_collect < T > ( iter : impl Iterator < Item = T > ) -> Result < Vec < T > , TryReserveError > {
686- let mut vec = Vec :: new ( ) ;
687- vec. try_extend ( iter) ?;
688- Ok ( vec)
689- }
690-
691675#[ doc( hidden) ]
692676pub fn try_new_repeat_item_in < T : Clone , A : Allocator > (
693677 item : T ,
0 commit comments