std-function

io::sink: discard output

A sink accepts bytes without keeping them. Useful for checking output-producing functions without retaining content, but not for validating that the resulting bytes are correct. Expected stdout (not executed): 7 Common mistake: Using a sink to verify output content.

Formal Syntax & Structure

rust syntaxrust
io::sink() -> Sink

Working Example

Example Snippetrust
fn main() {    use std::io::{self, Write};    let n = io::sink().write(b"discard").unwrap();    println!("{n}");}
Rust Reference