bufio_writer/bufio-writer.rs
1// Copyright 2023 The rust-ggstd authors.
2// Copyright 2009 The Go Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file.
5
6use ggstd::bufio;
7use std::io::Write;
8
9fn main() {
10 example_writer().unwrap();
11 // Output: Hello, world!
12}
13
14fn example_writer() -> std::io::Result<()> {
15 let stdout = std::io::stdout();
16 let mut stdout_lock = stdout.lock();
17 let mut w = bufio::Writer::new(&mut stdout_lock);
18 w.write_all(b"Hello, ")?;
19 w.write_all(b"world!")?;
20 w.flush()?; // Don't forget to flush!
21 Ok(())
22}