From ed5faa9ab86090b35d123e00c5629004d0896c12 Mon Sep 17 00:00:00 2001 From: Oliver Bunting <72926894+ollie-etl@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:27:23 +0000 Subject: [PATCH] Fix doctests --- src/fs/file.rs | 33 +++++++++++---------------------- src/lib.rs | 8 +++----- src/net/tcp/listener.rs | 4 ++-- src/net/tcp/stream.rs | 9 +++------ src/net/udp.rs | 27 ++++++++++----------------- src/net/unix/listener.rs | 4 ++-- src/net/unix/stream.rs | 3 +-- src/runtime/driver/op/mod.rs | 1 + src/runtime/mod.rs | 2 +- 9 files changed, 34 insertions(+), 57 deletions(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index 68dab6a1..9c3944cf 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -40,8 +40,7 @@ use std::path::Path; /// let file = File::create("hello.txt").await?; /// /// // Write some data -/// let (res, buf) = file.write_at(&b"hello world"[..], 0).submit().await; -/// let n = res?; +/// let (n, buf) = file.write_at(&b"hello world"[..], 0).submit().await?; /// /// println!("wrote {} bytes", n); /// @@ -166,8 +165,7 @@ impl File { /// let buffer = vec![0; 10]; /// /// // Read up to 10 bytes - /// let (res, buffer) = f.read_at(buffer, 0).await; - /// let n = res?; + /// let (n, buffer) = f.read_at(buffer, 0).await?; /// /// println!("The bytes: {:?}", &buffer[..n]); /// @@ -217,8 +215,7 @@ impl File { /// let buffers = vec![Vec::::with_capacity(10), Vec::::with_capacity(10)]; /// /// // Read up to 20 bytes - /// let (res, buffer) = f.readv_at(buffers, 0).await; - /// let n = res?; + /// let (n, _) = f.readv_at(buffers, 0).await?; /// /// println!("Read {} bytes", n); /// @@ -272,8 +269,7 @@ impl File { /// /// // Writes some prefix of the byte string, not necessarily all of it. /// let bufs = vec!["some".to_owned().into_bytes(), " bytes".to_owned().into_bytes()]; - /// let (res, _) = file.writev_at(bufs, 0).await; - /// let n = res?; + /// let (n, _) = file.writev_at(bufs, 0).await?; /// /// println!("wrote {} bytes", n); /// @@ -380,8 +376,7 @@ impl File { /// let buffer = Vec::with_capacity(10); /// /// // Read up to 10 bytes - /// let (res, buffer) = f.read_exact_at(buffer, 0).await; - /// res?; + /// let (_, buffer) = f.read_exact_at(buffer, 0).await?; /// /// println!("The bytes: {:?}", buffer); /// @@ -468,8 +463,7 @@ impl File { /// let buffer = registry.check_out(2).unwrap(); /// /// // Read up to 10 bytes - /// let (res, buffer) = f.read_fixed_at(buffer, 0).await; - /// let n = res?; + /// let (n, buffer) = f.read_fixed_at(buffer, 0).await?; /// /// println!("The bytes: {:?}", &buffer[..n]); /// @@ -521,8 +515,7 @@ impl File { /// let file = File::create("foo.txt").await?; /// /// // Writes some prefix of the byte string, not necessarily all of it. - /// let (res, _) = file.write_at(&b"some bytes"[..], 0).submit().await; - /// let n = res?; + /// let (n, _) = file.write_at(&b"some bytes"[..], 0).submit().await?; /// /// println!("wrote {} bytes", n); /// @@ -566,8 +559,7 @@ impl File { /// let file = File::create("foo.txt").await?; /// /// // Writes some prefix of the byte string, not necessarily all of it. - /// let (res, _) = file.write_all_at(&b"some bytes"[..], 0).await; - /// res?; + /// file.write_all_at(&b"some bytes"[..], 0).await?; /// /// println!("wrote all bytes"); /// @@ -655,8 +647,7 @@ impl File { /// /// // Writes some prefix of the buffer content, /// // not necessarily all of it. - /// let (res, _) = file.write_fixed_at(buffer, 0).await; - /// let n = res?; + /// let (n, _) = file.write_fixed_at(buffer, 0).await?; /// /// println!("wrote {} bytes", n); /// @@ -756,8 +747,7 @@ impl File { /// fn main() -> Result<(), Box> { /// tokio_uring::start(async { /// let f = File::create("foo.txt").await?; - /// let (res, buf) = f.write_at(&b"Hello, world!"[..], 0).submit().await; - /// let n = res?; + /// f.write_at(&b"Hello, world!"[..], 0).submit().await?; /// /// f.sync_all().await?; /// @@ -793,8 +783,7 @@ impl File { /// fn main() -> Result<(), Box> { /// tokio_uring::start(async { /// let f = File::create("foo.txt").await?; - /// let (res, buf) = f.write_at(&b"Hello, world!"[..], 0).submit().await; - /// let n = res?; + /// f.write_at(&b"Hello, world!"[..], 0).submit().await?; /// /// f.sync_data().await?; /// diff --git a/src/lib.rs b/src/lib.rs index c328c3ac..a9f5f9c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,8 +20,7 @@ //! // Read some data, the buffer is passed by ownership and //! // submitted to the kernel. When the operation completes, //! // we get the buffer back. -//! let (res, buf) = file.read_at(buf, 0).await; -//! let n = res?; +//! let (n, buf) = file.read_at(buf, 0).await?; //! //! // Display the contents //! println!("{:?}", &buf[..n]); @@ -116,8 +115,7 @@ use std::future::Future; /// // Read some data, the buffer is passed by ownership and /// // submitted to the kernel. When the operation completes, /// // we get the buffer back. -/// let (res, buf) = file.read_at(buf, 0).await; -/// let n = res?; +/// let (n, buf) = file.read_at(buf, 0).await?; /// /// // Display the contents /// println!("{:?}", &buf[..n]); @@ -308,7 +306,7 @@ impl sealed::MapResultBuf for Result { fn map_buf(self, f: impl FnOnce(B) -> U) -> Self::Output { match self { Ok((r, b)) => Ok((r, f(b))), - Err(e) => Err(e.map(|e| f(e))), + Err(e) => Err(e.map(f)), } } } diff --git a/src/net/tcp/listener.rs b/src/net/tcp/listener.rs index 2435c61b..6df26589 100644 --- a/src/net/tcp/listener.rs +++ b/src/net/tcp/listener.rs @@ -33,9 +33,9 @@ use std::{ /// let tx = TcpStream::connect("127.0.0.1:2345".parse().unwrap()).await.unwrap(); /// let rx = rx_ch.await.expect("The spawned task expected to send a TcpStream"); /// -/// tx.write(b"test" as &'static [u8]).submit().await.0.unwrap(); +/// tx.write(b"test" as &'static [u8]).submit().await.unwrap(); /// -/// let (_, buf) = rx.read(vec![0; 4]).await; +/// let (_, buf) = rx.read(vec![0; 4]).await.unwrap(); /// /// assert_eq!(buf, b"test"); /// }); diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index c9651a81..f135618d 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -28,8 +28,7 @@ use crate::{ /// let mut stream = TcpStream::connect("127.0.0.1:8080".parse().unwrap()).await?; /// /// // Write some data. -/// let (result, _) = stream.write(b"hello world!".as_slice()).submit().await; -/// result.unwrap(); +/// stream.write(b"hello world!".as_slice()).submit().await.unwrap(); /// /// Ok(()) /// }) @@ -137,15 +136,13 @@ impl TcpStream { /// let mut n = 0; /// let mut buf = vec![0u8; 4096]; /// loop { - /// let (result, nbuf) = stream.read(buf).await; + /// let (read, nbuf) = stream.read(buf).await.unwrap(); /// buf = nbuf; - /// let read = result.unwrap(); /// if read == 0 { /// break; /// } /// - /// let (res, slice) = stream.write_all(buf.slice(..read)).await; - /// let _ = res.unwrap(); + /// let (_, slice) = stream.write_all(buf.slice(..read)).await.unwrap(); /// buf = slice.into_inner(); /// n += read; /// } diff --git a/src/net/udp.rs b/src/net/udp.rs index 92529952..0714d88e 100644 --- a/src/net/udp.rs +++ b/src/net/udp.rs @@ -43,22 +43,18 @@ use std::{ /// let buf = vec![0; 32]; /// /// // write data -/// let (result, _) = socket.write(b"hello world".as_slice()).submit().await; -/// result.unwrap(); +/// socket.write(b"hello world".as_slice()).submit().await.unwrap(); /// /// // read data -/// let (result, buf) = other_socket.read(buf).await; -/// let n_bytes = result.unwrap(); +/// let (n_bytes, buf) = other_socket.read(buf).await.unwrap(); /// /// assert_eq!(b"hello world", &buf[..n_bytes]); /// /// // write data using send on connected socket -/// let (result, _) = socket.send(b"hello world via send".as_slice()).await; -/// result.unwrap(); +/// socket.send(b"hello world via send".as_slice()).await.unwrap(); /// /// // read data -/// let (result, buf) = other_socket.read(buf).await; -/// let n_bytes = result.unwrap(); +/// let (n_bytes, buf) = other_socket.read(buf).await.unwrap(); /// /// assert_eq!(b"hello world via send", &buf[..n_bytes]); /// @@ -83,12 +79,10 @@ use std::{ /// let buf = vec![0; 32]; /// /// // write data -/// let (result, _) = socket.send_to(b"hello world".as_slice(), second_addr).await; -/// result.unwrap(); +/// socket.send_to(b"hello world".as_slice(), second_addr).await.unwrap(); /// /// // read data -/// let (result, buf) = other_socket.recv_from(buf).await; -/// let (n_bytes, addr) = result.unwrap(); +/// let ((n_bytes, addr), buf) = other_socket.recv_from(buf).await.unwrap(); /// /// assert_eq!(addr, first_addr); /// assert_eq!(b"hello world", &buf[..n_bytes]); @@ -172,14 +166,13 @@ impl UdpSocket { /// let buf = vec![0; 32]; /// /// // write data - /// let (result, _) = std_socket + /// std_socket /// .send_to(b"hello world".as_slice(), second_addr) - /// .await; - /// result.unwrap(); + /// .await + /// .unwrap(); /// /// // read data - /// let (result, buf) = other_socket.recv_from(buf).await; - /// let (n_bytes, addr) = result.unwrap(); + /// let ((n_bytes, addr), buf) = other_socket.recv_from(buf).await.unwrap(); /// /// assert_eq!(addr, std_addr); /// assert_eq!(b"hello world", &buf[..n_bytes]); diff --git a/src/net/unix/listener.rs b/src/net/unix/listener.rs index ffabb5d2..b56f3f77 100644 --- a/src/net/unix/listener.rs +++ b/src/net/unix/listener.rs @@ -30,9 +30,9 @@ use std::{io, path::Path}; /// let tx = UnixStream::connect(&sock_file).await.unwrap(); /// let rx = rx_ch.await.expect("The spawned task expected to send a UnixStream"); /// -/// tx.write(b"test" as &'static [u8]).submit().await.0.unwrap(); +/// tx.write(b"test" as &'static [u8]).submit().await.unwrap(); /// -/// let (_, buf) = rx.read(vec![0; 4]).await; +/// let (_, buf) = rx.read(vec![0; 4]).await.unwrap(); /// /// assert_eq!(buf, b"test"); /// }); diff --git a/src/net/unix/stream.rs b/src/net/unix/stream.rs index d1ab6c41..8234b479 100644 --- a/src/net/unix/stream.rs +++ b/src/net/unix/stream.rs @@ -28,8 +28,7 @@ use std::{ /// let mut stream = UnixStream::connect("/tmp/tokio-uring-unix-test.sock").await?; /// /// // Write some data. -/// let (result, _) = stream.write(b"hello world!".as_slice()).submit().await; -/// result.unwrap(); +/// stream.write(b"hello world!".as_slice()).submit().await.unwrap(); /// /// Ok(()) /// }) diff --git a/src/runtime/driver/op/mod.rs b/src/runtime/driver/op/mod.rs index 32ba3e7a..7abc3030 100644 --- a/src/runtime/driver/op/mod.rs +++ b/src/runtime/driver/op/mod.rs @@ -165,6 +165,7 @@ pub(crate) enum Lifecycle { /// The submitter no longer has interest in the operation result. The state /// must be passed to the driver and held until the operation completes. + #[allow(dead_code)] Ignored(Box), /// The operation has completed with a single cqe result diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 369c060b..394c06b5 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -10,7 +10,7 @@ pub(crate) mod driver; pub(crate) use context::RuntimeContext; thread_local! { - pub(crate) static CONTEXT: RuntimeContext = RuntimeContext::new(); + pub(crate) static CONTEXT: RuntimeContext = const {RuntimeContext::new() }; } /// The Runtime Executor