Accept Into<SocketAddr> for network types
This commit is contained in:
parent
4afb537985
commit
3eee2a97ad
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -70,7 +70,7 @@ checksum = "5bdc16c6ce4c85d9b46b4e66f2a814be5b3f034dbd5131c268a24ca26d970db8"
|
|||
[[package]]
|
||||
name = "polldance"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.asonix.dog/safe-async/polldance#28909cce76e42d5c6310db780fb254f08e9627ef"
|
||||
source = "git+https://git.asonix.dog/safe-async/polldance#be0013e17ad46e94e9f1865b78dd29b2cbd5bd05"
|
||||
dependencies = [
|
||||
"rustix",
|
||||
]
|
||||
|
|
|
@ -6,7 +6,7 @@ use foxtrot::{
|
|||
use read_write_buf::ReadWriteBuf;
|
||||
|
||||
async fn echo(port: u16) -> Result<(), foxtrot::Error> {
|
||||
let listener = Async::bind([127, 0, 0, 1].into(), port).await?;
|
||||
let listener = Async::bind(([127, 0, 0, 1], port)).await?;
|
||||
println!("bound listener");
|
||||
|
||||
loop {
|
||||
|
|
10
src/io.rs
10
src/io.rs
|
@ -2,7 +2,7 @@ use crate::reactor::ReactorRef;
|
|||
use polldance::net::{TcpListener, TcpListenerBuilder, TcpStream, TcpStreamBuilder};
|
||||
use std::{
|
||||
future::Future,
|
||||
net::IpAddr,
|
||||
net::SocketAddr,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
|
@ -62,9 +62,9 @@ impl<T: AsFd + 'static> Drop for Async<T> {
|
|||
}
|
||||
|
||||
impl Async<TcpListener> {
|
||||
pub async fn bind(ip: IpAddr, port: u16) -> Result<Async<TcpListener>> {
|
||||
pub async fn bind<A: Into<SocketAddr>>(socket_address: A) -> Result<Async<TcpListener>> {
|
||||
Bind {
|
||||
io: Some(polldance::net::TcpListener::bind(ip, port).map(Arc::new)),
|
||||
io: Some(polldance::net::TcpListener::bind(socket_address).map(Arc::new)),
|
||||
}
|
||||
.await
|
||||
.map(Async::new)
|
||||
|
@ -78,9 +78,9 @@ impl Async<TcpListener> {
|
|||
}
|
||||
|
||||
impl Async<TcpStream> {
|
||||
pub async fn connect(ip: IpAddr, port: u16) -> Result<Async<TcpStream>> {
|
||||
pub async fn connect<A: Into<SocketAddr>>(socket_address: A) -> Result<Async<TcpStream>> {
|
||||
Connect {
|
||||
io: Some(polldance::net::TcpStream::connect(ip, port).map(Arc::new)),
|
||||
io: Some(polldance::net::TcpStream::connect(socket_address).map(Arc::new)),
|
||||
}
|
||||
.await
|
||||
.map(Async::new)
|
||||
|
|
Loading…
Reference in a new issue