about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBenoît du Garreau <bdgdlm@outlook.com>2024-05-20 17:00:11 +0200
committerBenoît du Garreau <bdgdlm@outlook.com>2024-05-20 17:00:11 +0200
commita197ff325989ed200fc4730d35501b9e4064316b (patch)
tree848f182da33618c098c3b1231ba304f7806d6cdb
parentcfb04795a1183ca59a4d63060f3443accb9e59bd (diff)
downloadrust-a197ff325989ed200fc4730d35501b9e4064316b.tar.gz
rust-a197ff325989ed200fc4730d35501b9e4064316b.zip
Address review comments
-rw-r--r--library/std/src/io/cursor.rs2
-rw-r--r--library/std/src/io/tests.rs32
2 files changed, 33 insertions, 1 deletions
diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs
index e6c53acacae..a1a8b2a3505 100644
--- a/library/std/src/io/cursor.rs
+++ b/library/std/src/io/cursor.rs
@@ -356,7 +356,7 @@ where
 
         match result {
             Ok(_) => self.pos += buf.len() as u64,
-            // The only posible error condition is EOF
+            // The only possible error condition is EOF, so place the cursor at "EOF"
             Err(_) => self.pos = self.inner.as_ref().len() as u64,
         }
 
diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs
index 090a091b09a..a2c1c430863 100644
--- a/library/std/src/io/tests.rs
+++ b/library/std/src/io/tests.rs
@@ -653,6 +653,38 @@ fn test_take_wrong_length() {
     let _ = reader.read(&mut buffer[..]);
 }
 
+#[test]
+fn slice_read_exact_eof() {
+    let slice = &b"123456"[..];
+
+    let mut r = slice;
+    assert!(r.read_exact(&mut [0; 10]).is_err());
+    assert!(r.is_empty());
+
+    let mut r = slice;
+    let buf = &mut [0; 10];
+    let mut buf = BorrowedBuf::from(buf.as_mut_slice());
+    assert!(r.read_buf_exact(buf.unfilled()).is_err());
+    assert!(r.is_empty());
+    assert_eq!(buf.filled(), b"123456");
+}
+
+#[test]
+fn cursor_read_exact_eof() {
+    let slice = Cursor::new(b"123456");
+
+    let mut r = slice.clone();
+    assert!(r.read_exact(&mut [0; 10]).is_err());
+    assert!(r.is_empty());
+
+    let mut r = slice;
+    let buf = &mut [0; 10];
+    let mut buf = BorrowedBuf::from(buf.as_mut_slice());
+    assert!(r.read_buf_exact(buf.unfilled()).is_err());
+    assert!(r.is_empty());
+    assert_eq!(buf.filled(), b"123456");
+}
+
 #[bench]
 fn bench_take_read(b: &mut test::Bencher) {
     b.iter(|| {