@@ -4,6 +4,8 @@ use std::any::Any;
44#[ cfg( feature="std" ) ]
55use std:: error:: Error ;
66
7+ use crate :: ArrayVec ;
8+
79/// Error value indicating insufficient capacity
810#[ derive( Clone , Copy , Eq , Ord , PartialEq , PartialOrd ) ]
911pub struct CapacityError < T = ( ) > {
@@ -48,23 +50,24 @@ impl<T> fmt::Debug for CapacityError<T> {
4850}
4951
5052/// Error value indicating that capacity is not completely filled
51- #[ derive( Clone , Copy , Debug , Eq , Ord , PartialEq , PartialOrd ) ]
52- pub struct UnderfilledError {
53- capacity : usize ,
54- len : usize ,
55- }
53+ #[ derive( Clone , Debug , Eq , Ord , PartialEq , PartialOrd ) ]
54+ pub struct UnderfilledError < T , const CAP : usize > ( ArrayVec < T , CAP > ) ;
55+
56+ impl < T , const CAP : usize > UnderfilledError < T , CAP > {
57+ pub const fn new ( inner : ArrayVec < T , CAP > ) -> Self {
58+ Self ( inner)
59+ }
5660
57- impl UnderfilledError {
58- pub const fn new ( capacity : usize , len : usize ) -> Self {
59- Self { capacity, len }
61+ pub fn take_vec ( self ) -> ArrayVec < T , CAP > {
62+ self . 0
6063 }
6164}
6265
6366#[ cfg( feature="std" ) ]
64- impl Error for UnderfilledError { }
67+ impl < T : fmt :: Debug , const CAP : usize > Error for UnderfilledError < T , CAP > { }
6568
66- impl fmt:: Display for UnderfilledError {
69+ impl < T , const CAP : usize > fmt:: Display for UnderfilledError < T , CAP > {
6770 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
68- write ! ( f, "capacity is not filled: expected {}, got {}" , self . capacity , self . len)
71+ write ! ( f, "capacity is not filled: expected {}, got {}" , CAP , self . 0 . len( ) )
6972 }
7073}
0 commit comments