Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cap-async-std/src/net/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl TcpListener {
///
/// This corresponds to [`async_std::net::TcpListener::incoming`].
#[inline]
pub fn incoming(&self) -> Incoming {
pub fn incoming(&self) -> Incoming<'_> {
let incoming = self.std.incoming();
Incoming::from_std(incoming)
}
Expand Down
2 changes: 1 addition & 1 deletion cap-async-std/src/os/unix/net/unix_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl UnixListener {
///
/// [`async_std::os::unix::net::UnixListener::incoming`]: https://docs.rs/async-std/latest/async_std/os/unix/net/struct.UnixListener.html#method.incoming
#[inline]
pub fn incoming(&self) -> Incoming {
pub fn incoming(&self) -> Incoming<'_> {
let incoming = self.std.incoming();
Incoming::from_std(incoming)
}
Expand Down
2 changes: 1 addition & 1 deletion cap-primitives/src/fs/via_parent/open_parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(super) fn open_parent<'path, 'borrow>(
/// - Append a `.` to a path with a trailing `..` to avoid requiring our
/// callers to special-case `..`.
/// - Bare absolute paths are ok.
fn split_parent(path: &Path) -> Option<(&Path, Component)> {
fn split_parent(path: &Path) -> Option<(&Path, Component<'_>)> {
if path.as_os_str().is_empty() {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion cap-std/src/net/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TcpListener {
///
/// This corresponds to [`std::net::TcpListener::incoming`].
#[inline]
pub fn incoming(&self) -> Incoming {
pub fn incoming(&self) -> Incoming<'_> {
let incoming = self.std.incoming();
Incoming::from_std(incoming)
}
Expand Down
2 changes: 1 addition & 1 deletion cap-std/src/os/unix/net/unix_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl UnixListener {
///
/// [`std::os::unix::net::UnixListener::incoming`]: https://doc.rust-lang.org/std/os/unix/net/struct.UnixListener.html#method.incoming
#[inline]
pub fn incoming(&self) -> Incoming {
pub fn incoming(&self) -> Incoming<'_> {
let incoming = self.std.incoming();
Incoming::from_std(incoming)
}
Expand Down
11 changes: 5 additions & 6 deletions examples/async_std_fs_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ async fn main() {
println!("`mkdir a`");

// Create a directory, returns `io::Result<()>`
match cwd.create_dir("a") {
Err(why) => println!("! {:?}", why.kind()),
Ok(_) => {}
if let Err(why) = cwd.create_dir("a") {
println!("! {:?}", why.kind())
}

println!("`echo hello > a/b.txt`");
// The previous match can be simplified using the `unwrap_or_else` method
echo("hello", &mut cwd, &Path::new("a/b.txt"))
echo("hello", &mut cwd, Path::new("a/b.txt"))
.await
.unwrap_or_else(|why| {
println!("! {:?}", why.kind());
Expand All @@ -65,7 +64,7 @@ async fn main() {
});

println!("`touch a/c/e.txt`");
touch(&mut cwd, &Path::new("a/c/e.txt"))
touch(&mut cwd, Path::new("a/c/e.txt"))
.await
.unwrap_or_else(|why| {
println!("! {:?}", why.kind());
Expand All @@ -83,7 +82,7 @@ async fn main() {
}

println!("`cat a/c/b.txt`");
match cat(&mut cwd, &Path::new("a/c/b.txt")).await {
match cat(&mut cwd, Path::new("a/c/b.txt")).await {
Err(why) => println!("! {:?}", why.kind()),
Ok(s) => println!("> {}", s),
}
Expand Down
11 changes: 5 additions & 6 deletions examples/std_fs_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ fn main() {
println!("`mkdir a`");

// Create a directory, returns `io::Result<()>`
match cwd.create_dir("a") {
Err(why) => println!("! {:?}", why.kind()),
Ok(_) => {}
if let Err(why) = cwd.create_dir("a") {
println!("! {:?}", why.kind())
}

println!("`echo hello > a/b.txt`");
// The previous match can be simplified using the `unwrap_or_else` method
echo("hello", &mut cwd, &Path::new("a/b.txt")).unwrap_or_else(|why| {
echo("hello", &mut cwd, Path::new("a/b.txt")).unwrap_or_else(|why| {
println!("! {:?}", why.kind());
});

Expand All @@ -57,7 +56,7 @@ fn main() {
});

println!("`touch a/c/e.txt`");
touch(&mut cwd, &Path::new("a/c/e.txt")).unwrap_or_else(|why| {
touch(&mut cwd, Path::new("a/c/e.txt")).unwrap_or_else(|why| {
println!("! {:?}", why.kind());
});

Expand All @@ -71,7 +70,7 @@ fn main() {
}

println!("`cat a/c/b.txt`");
match cat(&mut cwd, &Path::new("a/c/b.txt")) {
match cat(&mut cwd, Path::new("a/c/b.txt")) {
Err(why) => println!("! {:?}", why.kind()),
Ok(s) => println!("> {}", s),
}
Expand Down
64 changes: 31 additions & 33 deletions tests/cap-net-ext-udp-split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ fn socket_smoke_test_ip4() {
let client =
UdpSocket::new(AddressFamily::of_socket_addr(client_ip), Blocking::Yes).unwrap();
t!(client_pool
.udp_binder(&client_ip)
.udp_binder(client_ip)
.unwrap()
.bind_existing_udp_socket(&client));
rx1.recv().unwrap();
t!(p.send_to_udp_socket_addr(&client, &[99], &server_ip));
t!(p.send_to_udp_socket_addr(&client, &[99], server_ip));
tx2.send(()).unwrap();
});

let server =
UdpSocket::new(AddressFamily::of_socket_addr(server_ip), Blocking::Yes).unwrap();
t!(server_pool
.udp_binder(&server_ip)
.udp_binder(server_ip)
.unwrap()
.bind_existing_udp_socket(&server));
tx1.send(()).unwrap();
Expand All @@ -94,7 +94,7 @@ fn socket_name() {

let server = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&server));
assert_eq!(addr, t!(server.local_addr()));
Expand All @@ -111,15 +111,15 @@ fn socket_peer() {

let server = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
t!(pool1
.udp_binder(&addr1)
.udp_binder(addr1)
.unwrap()
.bind_existing_udp_socket(&server));
assert_eq!(
server.peer_addr().unwrap_err().kind(),
ErrorKind::NotConnected
);
t!(pool2
.udp_connecter(&addr2)
.udp_connecter(addr2)
.unwrap()
.connect_existing_udp_socket(&server));
assert_eq!(addr2, t!(server.peer_addr()));
Expand All @@ -136,20 +136,20 @@ fn udp_clone_smoke() {

let sock1 = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
t!(pool1
.udp_binder(&addr1)
.udp_binder(addr1)
.unwrap()
.bind_existing_udp_socket(&sock1));
let sock2 = UdpSocket::new(AddressFamily::of_socket_addr(addr2), Blocking::Yes).unwrap();
t!(pool2
.udp_binder(&addr2)
.udp_binder(addr2)
.unwrap()
.bind_existing_udp_socket(&sock2));

let _t = thread::spawn(move || {
let mut buf = [0, 0];
assert_eq!(sock2.recv_from(&mut buf).unwrap(), (1, addr1));
assert_eq!(buf[0], 1);
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], &addr1));
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], addr1));
});

let sock3 = t!(sock1.try_clone());
Expand All @@ -159,7 +159,7 @@ fn udp_clone_smoke() {
let p = pool2.clone();
let _t = thread::spawn(move || {
rx1.recv().unwrap();
t!(p.send_to_udp_socket_addr(&sock3, &[1], &addr2));
t!(p.send_to_udp_socket_addr(&sock3, &[1], addr2));
tx2.send(()).unwrap();
});
tx1.send(()).unwrap();
Expand All @@ -179,21 +179,21 @@ fn udp_clone_two_read() {

let sock1 = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
t!(pool1
.udp_binder(&addr1)
.udp_binder(addr1)
.unwrap()
.bind_existing_udp_socket(&sock1));
let sock2 = UdpSocket::new(AddressFamily::of_socket_addr(addr2), Blocking::Yes).unwrap();
t!(pool2
.udp_binder(&addr2)
.udp_binder(addr2)
.unwrap()
.bind_existing_udp_socket(&sock2));
let (tx1, rx) = channel();
let tx2 = tx1.clone();

let _t = thread::spawn(move || {
t!(pool1.send_to_udp_socket_addr(&sock2, &[1], &addr1));
t!(pool1.send_to_udp_socket_addr(&sock2, &[1], addr1));
rx.recv().unwrap();
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], &addr1));
t!(pool1.send_to_udp_socket_addr(&sock2, &[2], addr1));
rx.recv().unwrap();
});

Expand Down Expand Up @@ -224,12 +224,12 @@ fn udp_clone_two_write() {

let sock1 = UdpSocket::new(AddressFamily::of_socket_addr(addr1), Blocking::Yes).unwrap();
t!(pool1
.udp_binder(&addr1)
.udp_binder(addr1)
.unwrap()
.bind_existing_udp_socket(&sock1));
let sock2 = UdpSocket::new(AddressFamily::of_socket_addr(addr2), Blocking::Yes).unwrap();
t!(pool2
.udp_binder(&addr2)
.udp_binder(addr2)
.unwrap()
.bind_existing_udp_socket(&sock2));

Expand All @@ -249,12 +249,12 @@ fn udp_clone_two_write() {
let tx2 = tx.clone();
let p = pool2.clone();
let _t = thread::spawn(move || {
if p.send_to_udp_socket_addr(&sock3, &[1], &addr2).is_ok() {
if p.send_to_udp_socket_addr(&sock3, &[1], addr2).is_ok() {
let _ = tx2.send(());
}
done.send(()).unwrap();
});
if pool2.send_to_udp_socket_addr(&sock1, &[2], &addr2).is_ok() {
if pool2.send_to_udp_socket_addr(&sock1, &[2], addr2).is_ok() {
let _ = tx.send(());
}
drop(tx);
Expand Down Expand Up @@ -294,7 +294,7 @@ fn timeouts() {

let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&stream));
let dur = Duration::new(15410, 0);
Expand Down Expand Up @@ -325,7 +325,7 @@ fn test_read_timeout() {

let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&stream));
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));
Expand All @@ -336,8 +336,7 @@ fn test_read_timeout() {
loop {
let kind = stream
.recv_from(&mut buf)
.err()
.expect("expected error")
.expect_err("expected error")
.kind();
if kind != ErrorKind::Interrupted {
assert!(
Expand All @@ -360,12 +359,12 @@ fn test_read_with_timeout() {

let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&stream));
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));

t!(pool.send_to_udp_socket_addr(&stream, b"hello world", &addr));
t!(pool.send_to_udp_socket_addr(&stream, b"hello world", addr));

let mut buf = [0; 11];
t!(stream.recv_from(&mut buf));
Expand All @@ -375,8 +374,7 @@ fn test_read_with_timeout() {
loop {
let kind = stream
.recv_from(&mut buf)
.err()
.expect("expected error")
.expect_err("expected error")
.kind();
if kind != ErrorKind::Interrupted {
assert!(
Expand All @@ -401,7 +399,7 @@ fn test_timeout_zero_duration() {

let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&socket));

Expand All @@ -423,7 +421,7 @@ fn connect_send_recv() {

let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&socket));
t!(pool
Expand All @@ -446,7 +444,7 @@ fn connect_send_peek_recv() {

let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&socket));
t!(pool
Expand Down Expand Up @@ -478,10 +476,10 @@ fn peek_from() {

let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&socket));
t!(pool.send_to_udp_socket_addr(&socket, b"hello world", &addr));
t!(pool.send_to_udp_socket_addr(&socket, b"hello world", addr));

for _ in 1..3 {
let mut buf = [0; 11];
Expand All @@ -508,7 +506,7 @@ fn ttl() {

let stream = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&stream));

Expand All @@ -524,7 +522,7 @@ fn set_nonblocking() {

let socket = UdpSocket::new(AddressFamily::of_socket_addr(addr), Blocking::Yes).unwrap();
t!(pool
.udp_binder(&addr)
.udp_binder(addr)
.unwrap()
.bind_existing_udp_socket(&socket));

Expand Down
Loading
Loading