编写一个返回流流的函数
我正在尝试实现“连接”地址并从rustls
:
impl Connector {
...
fn connect(&self, address: String) -> rustls::Stream<ClientConnection, TcpStream> {
let target_address = address.parse().unwrap();
let server_name = rustls::ServerName::from(address).unwrap();
let mut tcp_stream = TcpStream::connect(target_address).unwrap();
let mut client_conn = rustls::ClientConnection::new(Arc::new(self.client_config), server_name).unwrap();
rustls::Stream::new(&mut client_conn, &mut tcp_stream)
}
这不起作用,因为client_conn
和tcp_stream
是借用的,这是不起作用的在功能中。和流
具有生命周期:
https:httpps:// docs。 rs/rustls/last/rustls/struct.stream.html
#[derive(Debug)]
pub struct Stream<'a, C: 'a + ?Sized, T: 'a + Read + Write + ?Sized> {
/// Our TLS connection
pub conn: &'a mut C,
/// The underlying transport, like a socket
pub sock: &'a mut T,
}
因此,如何在连接
函数中创建此stream
对象,并以LifeTime&gt;
I am trying to implement "connect" that takes address and returns the TLS connection from rustls
:
impl Connector {
...
fn connect(&self, address: String) -> rustls::Stream<ClientConnection, TcpStream> {
let target_address = address.parse().unwrap();
let server_name = rustls::ServerName::from(address).unwrap();
let mut tcp_stream = TcpStream::connect(target_address).unwrap();
let mut client_conn = rustls::ClientConnection::new(Arc::new(self.client_config), server_name).unwrap();
rustls::Stream::new(&mut client_conn, &mut tcp_stream)
}
This does not work because client_conn
and tcp_stream
were borrowed within the function. And Stream
has lifetime:
https://docs.rs/rustls/latest/rustls/struct.Stream.html
#[derive(Debug)]
pub struct Stream<'a, C: 'a + ?Sized, T: 'a + Read + Write + ?Sized> {
/// Our TLS connection
pub conn: &'a mut C,
/// The underlying transport, like a socket
pub sock: &'a mut T,
}
So, how do I create this Stream
object within the connect
function and returns accordingly with lifetime>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
流
是错误的数据类型。据我所知,它没有拥有连接对象的所有权。在文档中进行快速搜索使我相信您要搜索的是流式 。
I think
Stream
is the wrong data type. It does not take ownership of the connection objects as far as I can see.A quick search in the documentation makes me believe that what you are searching for is
StreamOwned
.