mirror of https://github.com/stjepang/smol
Merge pull request #25 from dignifiedquire/ideas-and-helpers
Ideas and helpers
This commit is contained in:
commit
eef5d79f48
|
@ -8,13 +8,13 @@ use std::future::Future;
|
|||
use std::io::{self, Read, Write};
|
||||
use std::net::{SocketAddr, TcpListener, TcpStream, ToSocketAddrs, UdpSocket};
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::io::{AsRawSocket, RawSocket};
|
||||
use std::os::windows::io::{AsRawSocket, IntoRawSocket, RawSocket};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
#[cfg(unix)]
|
||||
use std::{
|
||||
os::unix::io::{AsRawFd, RawFd},
|
||||
os::unix::io::{AsRawFd, IntoRawFd, RawFd},
|
||||
os::unix::net::{SocketAddr as UnixSocketAddr, UnixDatagram, UnixListener, UnixStream},
|
||||
path::Path,
|
||||
};
|
||||
|
@ -153,6 +153,12 @@ impl<T: AsRawFd> AsRawFd for Async<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
impl<T: IntoRawFd> IntoRawFd for Async<T> {
|
||||
fn into_raw_fd(self) -> RawFd {
|
||||
self.into_inner().unwrap().into_raw_fd()
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
impl<T: AsRawSocket> Async<T> {
|
||||
/// Creates an async I/O handle.
|
||||
|
@ -203,6 +209,13 @@ impl<T: AsRawSocket> AsRawSocket for Async<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
impl<T: IntowRawSocket> IntoRawSocket for Async<T> {
|
||||
fn into_raw_socket(self) -> RawSocket {
|
||||
self.into_inner().unwrap().into_raw_socket()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Async<T> {
|
||||
/// Gets a reference to the inner I/O handle.
|
||||
///
|
||||
|
|
|
@ -254,3 +254,11 @@ impl<T> Future for Task<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Into<async_task::JoinHandle<T, ()>> for Task<T> {
|
||||
fn into(mut self) -> async_task::JoinHandle<T, ()> {
|
||||
self.0
|
||||
.take()
|
||||
.expect("task was already canceled or has failed")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue