@@ -305,6 +305,24 @@ unsafe impl<const N: usize> IoBuf for arrayvec::ArrayVec<u8, N> {
305305 }
306306}
307307
308+ #[ cfg( feature = "smallvec" ) ]
309+ unsafe impl < const N : usize > IoBuf for smallvec:: SmallVec < [ u8 ; N ] >
310+ where
311+ [ u8 ; N ] : smallvec:: Array < Item = u8 > ,
312+ {
313+ fn as_buf_ptr ( & self ) -> * const u8 {
314+ self . as_ptr ( )
315+ }
316+
317+ fn buf_len ( & self ) -> usize {
318+ self . len ( )
319+ }
320+
321+ fn buf_capacity ( & self ) -> usize {
322+ self . capacity ( )
323+ }
324+ }
325+
308326/// A mutable compio compatible buffer.
309327///
310328/// The `IoBufMut` trait is implemented by buffer types that can be passed to
@@ -396,6 +414,16 @@ unsafe impl<const N: usize> IoBufMut for arrayvec::ArrayVec<u8, N> {
396414 }
397415}
398416
417+ #[ cfg( feature = "smallvec" ) ]
418+ unsafe impl < const N : usize > IoBufMut for smallvec:: SmallVec < [ u8 ; N ] >
419+ where
420+ [ u8 ; N ] : smallvec:: Array < Item = u8 > ,
421+ {
422+ fn as_buf_mut_ptr ( & mut self ) -> * mut u8 {
423+ self . as_mut_ptr ( )
424+ }
425+ }
426+
399427/// A helper trait for `set_len` like methods.
400428pub trait SetBufInit {
401429 /// Set the buffer length. If `len` is less than the current length, nothing
@@ -469,6 +497,18 @@ impl<const N: usize> SetBufInit for arrayvec::ArrayVec<u8, N> {
469497 }
470498}
471499
500+ #[ cfg( feature = "smallvec" ) ]
501+ impl < const N : usize > SetBufInit for smallvec:: SmallVec < [ u8 ; N ] >
502+ where
503+ [ u8 ; N ] : smallvec:: Array < Item = u8 > ,
504+ {
505+ unsafe fn set_buf_init ( & mut self , len : usize ) {
506+ if ( * * self ) . buf_len ( ) < len {
507+ self . set_len ( len) ;
508+ }
509+ }
510+ }
511+
472512impl < T : IoBufMut > SetBufInit for [ T ] {
473513 unsafe fn set_buf_init ( & mut self , len : usize ) {
474514 default_set_buf_init ( self . iter_mut ( ) , len)
@@ -496,6 +536,16 @@ impl<T: IoBufMut, const N: usize> SetBufInit for arrayvec::ArrayVec<T, N> {
496536 }
497537}
498538
539+ #[ cfg( feature = "smallvec" ) ]
540+ impl < T : IoBufMut , const N : usize > SetBufInit for smallvec:: SmallVec < [ T ; N ] >
541+ where
542+ [ T ; N ] : smallvec:: Array < Item = T > ,
543+ {
544+ unsafe fn set_buf_init ( & mut self , len : usize ) {
545+ default_set_buf_init ( self . iter_mut ( ) , len)
546+ }
547+ }
548+
499549unsafe fn default_set_buf_init < ' a , B : IoBufMut > (
500550 iter : impl IntoIterator < Item = & ' a mut B > ,
501551 mut len : usize ,
0 commit comments