mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-07-23 09:25:00 +00:00
feat: support for both Send and !Send Framed impls (#189)
Using GATs we achieve genericity over Send and Sync marker traits. The `FramedRead` and `FramedWrite` traits can now be used in both single-threaded and multi-threaded contexts.
This commit is contained in:
parent
37ac7052aa
commit
783167f23d
7 changed files with 190 additions and 44 deletions
|
@ -1,26 +1,27 @@
|
|||
use std::io;
|
||||
use std::pin::Pin;
|
||||
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use ironrdp_pdu::PduHint;
|
||||
|
||||
// TODO: use static async fn / return position impl trait in traits when stabiziled (https://github.com/rust-lang/rust/issues/91611)
|
||||
// TODO: investigate if we could use static async fn / return position impl trait in traits when stabilized:
|
||||
// https://github.com/rust-lang/rust/issues/91611
|
||||
|
||||
pub trait FramedRead {
|
||||
/// Reads from stream and fills internal buffer
|
||||
fn read<'a>(
|
||||
&'a mut self,
|
||||
buf: &'a mut BytesMut,
|
||||
) -> Pin<Box<dyn std::future::Future<Output = io::Result<usize>> + 'a>>
|
||||
type ReadFut<'read>: std::future::Future<Output = io::Result<usize>> + 'read
|
||||
where
|
||||
Self: 'a;
|
||||
Self: 'read;
|
||||
|
||||
/// Reads from stream and fills internal buffer
|
||||
fn read<'a>(&'a mut self, buf: &'a mut BytesMut) -> Self::ReadFut<'a>;
|
||||
}
|
||||
|
||||
pub trait FramedWrite {
|
||||
/// Writes an entire buffer into this stream.
|
||||
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> Pin<Box<dyn std::future::Future<Output = io::Result<()>> + 'a>>
|
||||
type WriteAllFut<'write>: std::future::Future<Output = io::Result<()>> + 'write
|
||||
where
|
||||
Self: 'a;
|
||||
Self: 'write;
|
||||
|
||||
/// Writes an entire buffer into this stream.
|
||||
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteAllFut<'a>;
|
||||
}
|
||||
|
||||
pub trait StreamWrapper: Sized {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue