Skip to content

Commit

Permalink
Fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
ollie-etl committed Feb 13, 2024
1 parent d84e764 commit ed5faa9
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 57 deletions.
33 changes: 11 additions & 22 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
///
Expand Down Expand Up @@ -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]);
///
Expand Down Expand Up @@ -217,8 +215,7 @@ impl File {
/// let buffers = vec![Vec::<u8>::with_capacity(10), Vec::<u8>::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);
///
Expand Down Expand Up @@ -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);
///
Expand Down Expand Up @@ -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);
///
Expand Down Expand Up @@ -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]);
///
Expand Down Expand Up @@ -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);
///
Expand Down Expand Up @@ -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");
///
Expand Down Expand Up @@ -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);
///
Expand Down Expand Up @@ -756,8 +747,7 @@ impl File {
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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?;
///
Expand Down Expand Up @@ -793,8 +783,7 @@ impl File {
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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?;
///
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -308,7 +306,7 @@ impl<T, B, U> sealed::MapResultBuf<B, U> for Result<T, B> {
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)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
/// });
Expand Down
9 changes: 3 additions & 6 deletions src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
/// })
Expand Down Expand Up @@ -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;
/// }
Expand Down
27 changes: 10 additions & 17 deletions src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
///
Expand All @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/net/unix/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
/// });
Expand Down
3 changes: 1 addition & 2 deletions src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
/// })
Expand Down
1 change: 1 addition & 0 deletions src/runtime/driver/op/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::any::Any>),

/// The operation has completed with a single cqe result
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed5faa9

Please sign in to comment.