1
1
#[ cfg( feature = "allocator_api" ) ]
2
2
use std:: alloc:: Allocator ;
3
- use std:: mem:: MaybeUninit ;
3
+ use std:: { mem:: MaybeUninit , rc :: Rc , sync :: Arc } ;
4
4
5
5
use crate :: * ;
6
6
@@ -126,7 +126,7 @@ unsafe impl<B: IoBuf + ?Sized> IoBuf for &'static mut B {
126
126
}
127
127
128
128
unsafe impl < B : IoBuf + ?Sized , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoBuf
129
- for box_alloc ! ( B , A )
129
+ for t_alloc ! ( Box , B , A )
130
130
{
131
131
fn as_buf_ptr ( & self ) -> * const u8 {
132
132
( * * self ) . as_buf_ptr ( )
@@ -141,7 +141,41 @@ unsafe impl<B: IoBuf + ?Sized, #[cfg(feature = "allocator_api")] A: Allocator +
141
141
}
142
142
}
143
143
144
- unsafe impl < #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoBuf for vec_alloc ! ( u8 , A ) {
144
+ unsafe impl < B : IoBuf + ?Sized , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoBuf
145
+ for t_alloc ! ( Rc , B , A )
146
+ {
147
+ fn as_buf_ptr ( & self ) -> * const u8 {
148
+ ( * * self ) . as_buf_ptr ( )
149
+ }
150
+
151
+ fn buf_len ( & self ) -> usize {
152
+ ( * * self ) . buf_len ( )
153
+ }
154
+
155
+ fn buf_capacity ( & self ) -> usize {
156
+ ( * * self ) . buf_capacity ( )
157
+ }
158
+ }
159
+
160
+ unsafe impl < B : IoBuf + ?Sized , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoBuf
161
+ for t_alloc ! ( Arc , B , A )
162
+ {
163
+ fn as_buf_ptr ( & self ) -> * const u8 {
164
+ ( * * self ) . as_buf_ptr ( )
165
+ }
166
+
167
+ fn buf_len ( & self ) -> usize {
168
+ ( * * self ) . buf_len ( )
169
+ }
170
+
171
+ fn buf_capacity ( & self ) -> usize {
172
+ ( * * self ) . buf_capacity ( )
173
+ }
174
+ }
175
+
176
+ unsafe impl < #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoBuf
177
+ for t_alloc ! ( Vec , u8 , A )
178
+ {
145
179
fn as_buf_ptr ( & self ) -> * const u8 {
146
180
self . as_ptr ( )
147
181
}
@@ -314,15 +348,15 @@ unsafe impl<B: IoBufMut + ?Sized> IoBufMut for &'static mut B {
314
348
}
315
349
316
350
unsafe impl < B : IoBufMut + ?Sized , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoBufMut
317
- for box_alloc ! ( B , A )
351
+ for t_alloc ! ( Box , B , A )
318
352
{
319
353
fn as_buf_mut_ptr ( & mut self ) -> * mut u8 {
320
354
( * * self ) . as_buf_mut_ptr ( )
321
355
}
322
356
}
323
357
324
358
unsafe impl < #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoBufMut
325
- for vec_alloc ! ( u8 , A )
359
+ for t_alloc ! ( Vec , u8 , A )
326
360
{
327
361
fn as_buf_mut_ptr ( & mut self ) -> * mut u8 {
328
362
self . as_mut_ptr ( )
@@ -449,7 +483,7 @@ impl<T: IoBuf, const N: usize> IoVectoredBuf for [T; N] {
449
483
}
450
484
451
485
impl < T : IoBuf , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoVectoredBuf
452
- for vec_alloc ! ( T , A )
486
+ for t_alloc ! ( Vec , T , A )
453
487
{
454
488
fn as_dyn_bufs ( & self ) -> impl Iterator < Item = & dyn IoBuf > {
455
489
self . iter ( ) . map ( |buf| buf as & dyn IoBuf )
@@ -540,7 +574,7 @@ impl<T: IoBufMut, const N: usize> IoVectoredBufMut for [T; N] {
540
574
}
541
575
542
576
impl < T : IoBufMut , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoVectoredBufMut
543
- for vec_alloc ! ( T , A )
577
+ for t_alloc ! ( Vec , T , A )
544
578
{
545
579
fn as_dyn_mut_bufs ( & mut self ) -> impl Iterator < Item = & mut dyn IoBufMut > {
546
580
self . iter_mut ( ) . map ( |buf| buf as & mut dyn IoBufMut )
@@ -599,7 +633,7 @@ impl<T: IoBuf, const N: usize> IoIndexedBuf for [T; N] {
599
633
}
600
634
601
635
impl < T : IoBuf , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoIndexedBuf
602
- for vec_alloc ! ( T , A )
636
+ for t_alloc ! ( Vec , T , A )
603
637
{
604
638
fn buf_nth ( & self , n : usize ) -> Option < & dyn IoBuf > {
605
639
self . get ( n) . map ( |b| b as _ )
@@ -638,7 +672,7 @@ impl<T: IoBufMut, const N: usize> IoIndexedBufMut for [T; N] {
638
672
}
639
673
640
674
impl < T : IoBufMut , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > IoIndexedBufMut
641
- for vec_alloc ! ( T , A )
675
+ for t_alloc ! ( Vec , T , A )
642
676
{
643
677
fn buf_nth_mut ( & mut self , n : usize ) -> Option < & mut dyn IoBufMut > {
644
678
self . get_mut ( n) . map ( |b| b as _ )
@@ -670,14 +704,14 @@ impl<B: SetBufInit + ?Sized> SetBufInit for &'static mut B {
670
704
}
671
705
672
706
impl < B : SetBufInit + ?Sized , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > SetBufInit
673
- for box_alloc ! ( B , A )
707
+ for t_alloc ! ( Box , B , A )
674
708
{
675
709
unsafe fn set_buf_init ( & mut self , len : usize ) {
676
710
( * * self ) . set_buf_init ( len)
677
711
}
678
712
}
679
713
680
- impl < #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > SetBufInit for vec_alloc ! ( u8 , A ) {
714
+ impl < #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > SetBufInit for t_alloc ! ( Vec , u8 , A ) {
681
715
unsafe fn set_buf_init ( & mut self , len : usize ) {
682
716
if ( * * self ) . buf_len ( ) < len {
683
717
self . set_len ( len) ;
@@ -738,7 +772,7 @@ impl<T: IoBufMut, const N: usize> SetBufInit for [T; N] {
738
772
}
739
773
740
774
impl < T : IoBufMut , #[ cfg( feature = "allocator_api" ) ] A : Allocator + ' static > SetBufInit
741
- for vec_alloc ! ( T , A )
775
+ for t_alloc ! ( Vec , T , A )
742
776
{
743
777
unsafe fn set_buf_init ( & mut self , len : usize ) {
744
778
default_set_buf_init ( self . iter_mut ( ) , len)
0 commit comments