Skip to content

Commit 5d8a495

Browse files
committed
Update BufResult<T, B> to be Result<(T,B), BufError<B>>
1 parent 34b27ab commit 5d8a495

27 files changed

+195
-176
lines changed

examples/cat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ fn main() {
2929

3030
loop {
3131
// Read a chunk
32-
let (res, b) = file.read_at(buf, pos).await;
33-
let n = res.unwrap();
32+
let (n, b) = file.read_at(buf, pos).await.unwrap();
3433

3534
if n == 0 {
3635
break;

examples/mix.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ fn main() {
3434

3535
loop {
3636
// Read a chunk
37-
let (res, b) = file.read_at(buf, pos).await;
38-
let n = res.unwrap();
37+
let (n, b) = file.read_at(buf, pos).await.unwrap();
3938

4039
if n == 0 {
4140
break;
4241
}
4342

44-
let (res, b) = socket.write(b).submit().await;
45-
pos += res.unwrap() as u64;
43+
let (written, b) = socket.write(b).submit().await.unwrap();
44+
pos += written as u64;
4645

4746
buf = b;
4847
}

examples/tcp_listener.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ fn main() {
2929

3030
let mut buf = vec![0u8; 4096];
3131
loop {
32-
let (result, nbuf) = stream.read(buf).await;
32+
let (read, nbuf) = stream.read(buf).await.unwrap();
3333
buf = nbuf;
34-
let read = result.unwrap();
3534
if read == 0 {
3635
println!("{} closed, {} total ping-ponged", socket_addr, n);
3736
break;
3837
}
3938

40-
let (res, slice) = stream.write_all(buf.slice(..read)).await;
41-
let _ = res.unwrap();
39+
let (_, slice) = stream.write_all(buf.slice(..read)).await.unwrap();
4240
buf = slice.into_inner();
4341
println!("{} all {} bytes ping-ponged", socket_addr, read);
4442
n += read;

examples/tcp_listener_fixed_buffers.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,15 @@ async fn echo_handler<T: IoBufMut>(
7979
// Each time through the loop, use fbuf and then get it back for the next
8080
// iteration.
8181

82-
let (result, fbuf1) = stream.read_fixed(fbuf).await;
82+
let (read, fbuf1) = stream.read_fixed(fbuf).await.unwrap();
8383
fbuf = {
84-
let read = result.unwrap();
8584
if read == 0 {
8685
break;
8786
}
8887
assert_eq!(4096, fbuf1.len()); // To prove a point.
8988

90-
let (res, nslice) = stream.write_fixed_all(fbuf1.slice(..read)).await;
89+
let (_, nslice) = stream.write_fixed_all(fbuf1.slice(..read)).await.unwrap();
9190

92-
let _ = res.unwrap();
9391
println!("peer {} all {} bytes ping-ponged", peer, read);
9492
n += read;
9593

examples/tcp_stream.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ fn main() {
1515
let stream = TcpStream::connect(socket_addr).await.unwrap();
1616
let buf = vec![1u8; 128];
1717

18-
let (result, buf) = stream.write(buf).submit().await;
19-
println!("written: {}", result.unwrap());
18+
let (written, buf) = stream.write(buf).submit().await.unwrap();
19+
println!("written: {}", written);
2020

21-
let (result, buf) = stream.read(buf).await;
22-
let read = result.unwrap();
21+
let (read, buf) = stream.read(buf).await.unwrap();
2322
println!("read: {:?}", &buf[..read]);
2423
});
2524
}

examples/udp_socket.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ fn main() {
1515

1616
let buf = vec![0u8; 128];
1717

18-
let (result, mut buf) = socket.recv_from(buf).await;
19-
let (read, socket_addr) = result.unwrap();
18+
let ((read, socket_addr), mut buf) = socket.recv_from(buf).await.unwrap();
2019
buf.resize(read, 0);
2120
println!("received from {}: {:?}", socket_addr, &buf[..]);
2221

23-
let (result, _buf) = socket.send_to(buf, socket_addr).await;
24-
println!("sent to {}: {}", socket_addr, result.unwrap());
22+
let (sent, _buf) = socket.send_to(buf, socket_addr).await.unwrap();
23+
println!("sent to {}: {}", socket_addr, sent);
2524
});
2625
}

examples/unix_listener.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ fn main() {
2020
tokio_uring::spawn(async move {
2121
let buf = vec![1u8; 128];
2222

23-
let (result, buf) = stream.write(buf).submit().await;
24-
println!("written to {}: {}", &socket_addr, result.unwrap());
23+
let (written, buf) = stream.write(buf).submit().await.unwrap();
24+
println!("written to {}: {}", &socket_addr, written);
2525

26-
let (result, buf) = stream.read(buf).await;
27-
let read = result.unwrap();
26+
let (read, buf) = stream.read(buf).await.unwrap();
2827
println!("read from {}: {:?}", &socket_addr, &buf[..read]);
2928
});
3029
}

examples/unix_stream.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ fn main() {
1515
let stream = UnixStream::connect(socket_addr).await.unwrap();
1616
let buf = vec![1u8; 128];
1717

18-
let (result, buf) = stream.write(buf).submit().await;
19-
println!("written: {}", result.unwrap());
18+
let (written, buf) = stream.write(buf).submit().await.unwrap();
19+
println!("written: {}", written);
2020

21-
let (result, buf) = stream.read(buf).await;
22-
let read = result.unwrap();
21+
let (read, buf) = stream.read(buf).await.unwrap();
2322
println!("read: {:?}", &buf[..read]);
2423
});
2524
}

examples/wrk-bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ fn main() -> io::Result<()> {
2121
let (stream, _) = listener.accept().await?;
2222

2323
tokio_uring::spawn(async move {
24-
let (result, _) = stream.write(RESPONSE).submit().await;
24+
let result = stream.write(RESPONSE).submit().await;
2525

2626
if let Err(err) = result {
27-
eprintln!("Client connection failed: {}", err);
27+
eprintln!("Client connection failed: {}", err.0);
2828
}
2929
});
3030
}

src/buf/slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::ops;
2323
///
2424
/// assert_eq!(&slice[..], b"hello");
2525
/// ```
26+
#[derive(Debug)]
2627
pub struct Slice<T> {
2728
buf: T,
2829
begin: usize,

0 commit comments

Comments
 (0)