helloworld_noflush/
helloworld-noflush.rs

1//! Simple hello world example using asynchronous stdio. This also illustrates the auto-flush
2//! capability of the library, which matches the standard lib.
3extern crate futures_lite;
4extern crate async_blocking_stdio as astdio;
5
6use futures_lite::io::AsyncWriteExt;
7
8fn main() -> std::io::Result<()> {
9    futures_lite::future::block_on(async {
10        let mut stdout_handle = astdio::stdout().lock().await;
11        // Note how we do not need to bother flushing this - it's auto-handled by the crate
12        stdout_handle.write_all(b"Hello world!\n").await
13    })
14}
15
16// async-blocking-stdio - std::io::std{in(), out(), err()}, but async
17// Copyright (C) 2024  Matti Bryce <mattibryce at protonmail dot com>
18//
19// This program is free software: you can redistribute it and/or modify
20// it under the terms of the GNU General Public License as published by
21// the Free Software Foundation, either version 3 of the License, or
22// (at your option) any later version.
23//
24// This program is distributed in the hope that it will be useful,
25// but WITHOUT ANY WARRANTY; without even the implied warranty of
26// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27// GNU General Public License for more details.
28//
29// You should have received a copy of the GNU General Public License
30// along with this program.  If not, see <https://www.gnu.org/licenses/>.