helloworld_re_syncify/helloworld-re-syncify.rs
1//! Illustrates the feature of this library that lets you use the synchronous stdio functionality
2//! upon the async streams, with some trivial code adjustments.
3extern crate async_blocking_stdio as astdio;
4extern crate futures_lite;
5
6fn main() -> std::io::Result<()> {
7 futures_lite::future::block_on(async {
8 use std::io::Write;
9 let mut stdout_sync_handle = astdio::stdout().lock_into_sync().await;
10 // Note how we do not need to bother flushing this - it's auto-handled by the crate, and is
11 // basically just println! here.
12 //
13 // However - in reality, this is not ideal because `BlockOn` uses
14 // futures_lite::future::block_on internally - it's better to use the async traits
15 // internally where possible if you're inside a future like this.
16 writeln!(stdout_sync_handle, "Hello world, from sync!")
17 })
18}
19
20// async-blocking-stdio - std::io::std{in(), out(), err()}, but async
21// Copyright (C) 2024 Matti Bryce <mattibryce at protonmail dot com>
22//
23// This program is free software: you can redistribute it and/or modify
24// it under the terms of the GNU General Public License as published by
25// the Free Software Foundation, either version 3 of the License, or
26// (at your option) any later version.
27//
28// This program is distributed in the hope that it will be useful,
29// but WITHOUT ANY WARRANTY; without even the implied warranty of
30// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31// GNU General Public License for more details.
32//
33// You should have received a copy of the GNU General Public License
34// along with this program. If not, see <https://www.gnu.org/licenses/>.