1
- use std:: future:: Future ;
2
-
3
- use cxx:: UniquePtr ;
1
+ use std:: { future:: Future , pin:: Pin } ;
4
2
5
3
pub type Result < T > = std:: io:: Result < T > ;
6
4
@@ -406,7 +404,7 @@ impl<T> AsyncWriteAdapter<T> {
406
404
407
405
impl < T : AsyncInputStream + Unpin > futures:: io:: AsyncRead for AsyncReadAdapter < T > {
408
406
fn poll_read (
409
- mut self : std :: pin :: Pin < & mut Self > ,
407
+ mut self : Pin < & mut Self > ,
410
408
cx : & mut std:: task:: Context < ' _ > ,
411
409
buf : & mut [ u8 ] ,
412
410
) -> std:: task:: Poll < std:: io:: Result < usize > > {
@@ -426,7 +424,7 @@ impl<T: AsyncInputStream + Unpin> futures::io::AsyncRead for AsyncReadAdapter<T>
426
424
427
425
impl < T : AsyncOutputStream + Unpin > futures:: io:: AsyncWrite for AsyncWriteAdapter < T > {
428
426
fn poll_write (
429
- mut self : std :: pin :: Pin < & mut Self > ,
427
+ mut self : Pin < & mut Self > ,
430
428
cx : & mut std:: task:: Context < ' _ > ,
431
429
buf : & [ u8 ] ,
432
430
) -> std:: task:: Poll < std:: io:: Result < usize > > {
@@ -443,15 +441,15 @@ impl<T: AsyncOutputStream + Unpin> futures::io::AsyncWrite for AsyncWriteAdapter
443
441
}
444
442
445
443
fn poll_flush (
446
- self : std :: pin :: Pin < & mut Self > ,
444
+ self : Pin < & mut Self > ,
447
445
_cx : & mut std:: task:: Context < ' _ > ,
448
446
) -> std:: task:: Poll < std:: io:: Result < ( ) > > {
449
447
// KJ streams don't have explicit flush, so we just return ready
450
448
std:: task:: Poll :: Ready ( Ok ( ( ) ) )
451
449
}
452
450
453
451
fn poll_close (
454
- self : std :: pin :: Pin < & mut Self > ,
452
+ self : Pin < & mut Self > ,
455
453
_cx : & mut std:: task:: Context < ' _ > ,
456
454
) -> std:: task:: Poll < std:: io:: Result < ( ) > > {
457
455
// KJ streams don't have explicit close, so we just return ready
@@ -563,26 +561,20 @@ pub fn cxx_to_io_error(e: cxx::Exception) -> std::io::Error {
563
561
}
564
562
565
563
/// Rust wrapper for the `CxxAsyncInputStream` FFI type
566
- pub struct CxxAsyncInputStream {
567
- inner : UniquePtr < ffi:: CxxAsyncInputStream > ,
564
+ pub struct CxxAsyncInputStream < ' a > {
565
+ inner : Pin < & ' a mut ffi:: CxxAsyncInputStream > ,
568
566
}
569
567
570
- impl CxxAsyncInputStream {
571
- /// Create a new `CxxAsyncInputStream` from the FFI type
572
- pub fn new ( inner : UniquePtr < ffi:: CxxAsyncInputStream > ) -> Self {
568
+ impl < ' a > CxxAsyncInputStream < ' a > {
569
+ pub fn new ( inner : Pin < & ' a mut ffi:: CxxAsyncInputStream > ) -> Self {
573
570
Self { inner }
574
571
}
575
572
}
576
573
577
- impl AsyncInputStream for CxxAsyncInputStream {
578
- async fn try_read (
579
- & mut self ,
580
- buffer : & mut [ u8 ] ,
581
- min_bytes : usize ,
582
- ) -> Result < usize > {
574
+ impl < ' a > AsyncInputStream for CxxAsyncInputStream < ' a > {
575
+ async fn try_read ( & mut self , buffer : & mut [ u8 ] , min_bytes : usize ) -> Result < usize > {
583
576
self . inner
584
577
. as_mut ( )
585
- . expect ( "CxxAsyncInputStream is null" )
586
578
. try_read ( buffer, min_bytes)
587
579
. await
588
580
. map_err ( cxx_to_io_error)
@@ -605,20 +597,17 @@ impl AsyncInputStream for CxxAsyncInputStream {
605
597
}
606
598
607
599
/// Rust wrapper for the `CxxAsyncOutputStream` FFI type
608
- pub struct CxxAsyncOutputStream {
609
- inner : std :: pin :: Pin < Box < ffi:: CxxAsyncOutputStream > > ,
600
+ pub struct CxxAsyncOutputStream < ' a > {
601
+ inner : Pin < & ' a mut ffi:: CxxAsyncOutputStream > ,
610
602
}
611
603
612
- impl CxxAsyncOutputStream {
613
- /// Create a new `CxxAsyncOutputStream` from the FFI type
614
- pub fn new ( ffi_stream : ffi:: CxxAsyncOutputStream ) -> Self {
615
- Self {
616
- inner : Box :: pin ( ffi_stream) ,
617
- }
604
+ impl < ' a > CxxAsyncOutputStream < ' a > {
605
+ pub fn new ( inner : Pin < & ' a mut ffi:: CxxAsyncOutputStream > ) -> Self {
606
+ Self { inner }
618
607
}
619
608
}
620
609
621
- impl AsyncOutputStream for CxxAsyncOutputStream {
610
+ impl < ' a > AsyncOutputStream for CxxAsyncOutputStream < ' a > {
622
611
async fn write ( & mut self , buffer : & [ u8 ] ) -> Result < ( ) > {
623
612
self . inner
624
613
. as_mut ( )
@@ -655,25 +644,18 @@ impl AsyncOutputStream for CxxAsyncOutputStream {
655
644
}
656
645
657
646
/// Rust wrapper for the `CxxAsyncIoStream` FFI type
658
- pub struct CxxAsyncIoStream {
659
- inner : std :: pin :: Pin < Box < ffi:: CxxAsyncIoStream > > ,
647
+ pub struct CxxAsyncIoStream < ' a > {
648
+ inner : Pin < & ' a mut ffi:: CxxAsyncIoStream > ,
660
649
}
661
650
662
- impl CxxAsyncIoStream {
663
- /// Create a new `CxxAsyncIoStream` from the FFI type
664
- pub fn new ( ffi_stream : ffi:: CxxAsyncIoStream ) -> Self {
665
- Self {
666
- inner : Box :: pin ( ffi_stream) ,
667
- }
651
+ impl < ' a > CxxAsyncIoStream < ' a > {
652
+ pub fn new ( inner : Pin < & ' a mut ffi:: CxxAsyncIoStream > ) -> Self {
653
+ Self { inner }
668
654
}
669
655
}
670
656
671
- impl AsyncInputStream for CxxAsyncIoStream {
672
- async fn try_read (
673
- & mut self ,
674
- buffer : & mut [ u8 ] ,
675
- min_bytes : usize ,
676
- ) -> Result < usize > {
657
+ impl < ' a > AsyncInputStream for CxxAsyncIoStream < ' a > {
658
+ async fn try_read ( & mut self , buffer : & mut [ u8 ] , min_bytes : usize ) -> Result < usize > {
677
659
self . inner
678
660
. as_mut ( )
679
661
. try_read ( buffer, min_bytes)
@@ -697,7 +679,7 @@ impl AsyncInputStream for CxxAsyncIoStream {
697
679
}
698
680
}
699
681
700
- impl AsyncOutputStream for CxxAsyncIoStream {
682
+ impl < ' a > AsyncOutputStream for CxxAsyncIoStream < ' a > {
701
683
async fn write ( & mut self , buffer : & [ u8 ] ) -> Result < ( ) > {
702
684
self . inner
703
685
. as_mut ( )
@@ -733,7 +715,7 @@ impl AsyncOutputStream for CxxAsyncIoStream {
733
715
}
734
716
}
735
717
736
- impl AsyncIoStream for CxxAsyncIoStream {
718
+ impl < ' a > AsyncIoStream for CxxAsyncIoStream < ' a > {
737
719
async fn shutdown_write ( & mut self ) -> Result < ( ) > {
738
720
self . inner . as_mut ( ) . shutdown_write ( ) ;
739
721
Ok ( ( ) )
0 commit comments