From 3e4a34ce682fe9c5508098f41634fa69f4cfc98d Mon Sep 17 00:00:00 2001 From: AmanBoronbaev <149809343+AmanBoronbaev@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:59:41 +0300 Subject: [PATCH] Use a byte buffer to explain testing std::io::Write output --- src/tutorial/testing.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/tutorial/testing.md b/src/tutorial/testing.md index 0d9af6d..be5ed6c 100644 --- a/src/tutorial/testing.md +++ b/src/tutorial/testing.md @@ -168,8 +168,8 @@ We'll need to capture the output somehow. Rust's standard library has some neat abstractions for dealing with I/O (input/output), and we'll make use of one called [`std::io::Write`]. -This is a [trait][trpl-traits] that abstracts over things we can write to, -which includes strings and `stdout`. +This [trait][trpl-traits] describes destinations for bytes, +including an in-memory `Vec` and `stdout`. [trpl-traits]: https://doc.rust-lang.org/book/ch10-02-traits.html [`std::io::Write`]: https://doc.rust-lang.org/1.39.0/std/io/trait.Write.html @@ -204,10 +204,8 @@ to see a list of "Implementors". With that knowledge, let's change our function to accept a third parameter. It can be any type that implements `Write`. -This way, -we can supply a simple string -in our tests -and make assertions on it. +In the test we can pass a mutable reference to a `Vec` +and compare the bytes written to it with a byte string literal. Here is how we can write this version of `find_matches`: ```rust,ignore