Skip to content

Commit

Permalink
Merge pull request #25 from dignifiedquire/ideas-and-helpers
Browse files Browse the repository at this point in the history
Ideas and helpers
  • Loading branch information
Stjepan Glavina authored Apr 25, 2020
2 parents 55f360b + 9b44f7f commit eef5d79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/async_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
///
Expand Down
8 changes: 8 additions & 0 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit eef5d79

Please sign in to comment.