devela/sys/io/namespace.rs
1// devela::sys::io::namespace
2//
3//! `Io` namespace.
4//
5
6#[cfg(not(feature = "std"))]
7use super::{io_copy as copy, io_empty as empty, io_repeat as repeat};
8#[cfg(feature = "std")]
9use crate::{
10 _dep::_std::io::{copy, empty, read_to_string, repeat, sink, stderr, stdin, stdout},
11 IoSink, Stderr, Stdin, Stdout, String,
12};
13use crate::{IoEmpty, IoRead, IoRepeat, IoResult, IoWrite};
14
15#[doc = crate::TAG_NAMESPACE!()]
16/// I/O-related operations.
17pub struct Io;
18
19/// # Methods available in `no_std`.
20#[rustfmt::skip]
21impl Io {
22 #[cfg(not(feature = "std"))]
23 /// Copies the entire contents of a reader into a writer.
24 ///
25 /// See <https://doc.rust-lang.org/std/io/fn.copy.html>.
26 ///
27 /// # Features
28 /// Makes use of the `unsafe_array` feature to employ [`MaybeUninit`].
29 pub fn copy<R, W, const LEN: usize>(reader: &mut R, writer: &mut W) -> IoResult<u64>
30 where R: IoRead + ?Sized, W: IoWrite + ?Sized { copy::<R, W, LEN>(reader, writer) }
31 #[cfg(feature = "std")]
32 /// Copies the entire contents of a reader into a writer.
33 ///
34 /// See `std::io::`[`copy`].
35 pub fn copy<R, W>(reader: &mut R, writer: &mut W) -> IoResult<u64>
36 where R: IoRead + ?Sized, W: IoWrite + ?Sized { copy(reader, writer) }
37
38 /// Creates a value that is always at EOF for reads, and ignores all data written.
39 ///
40 /// See `std::io::`[`empty`].
41 ///
42 /// [`empty`]: ::std::io::empty
43 #[must_use]
44 pub const fn empty() -> IoEmpty { empty() }
45
46 /// Creates an instance of a reader that infinitely repeats one byte.
47 ///
48 /// See `std::io::`[`repeat`].
49 ///
50 /// [`repeat`]: ::std::io::repeat
51 #[must_use]
52 pub const fn repeat(byte: u8) -> IoRepeat { repeat(byte) }
53}
54
55/// # Methods only available in `std`.
56#[rustfmt::skip]
57#[cfg(feature = "std")]
58#[cfg_attr(nightly_doc, doc(cfg(feature = "std")))]
59impl Io {
60 /// Reads all bytes from a reader into a new String.
61 ///
62 /// See `std::io::`[`read_to_string`].
63 pub fn read_to_string<R: IoRead>(reader: R) -> IoResult<String> { read_to_string(reader) }
64
65 /// Creates an instance of a writer which will successfully consume all data.
66 ///
67 /// See `std::io::`[`sink`].
68 pub const fn sink() -> IoSink { sink() }
69
70 /// Constructs a new handle to the standard error of the current process.
71 ///
72 /// See `std::io::`[`stderr`].
73 pub fn stderr() -> Stderr { stderr() }
74
75 /// Constructs a new handle to the standard input of the current process.
76 ///
77 /// See `std::io::`[`stdin`].
78 pub fn stdin() -> Stdin { stdin() }
79
80 /// Constructs a new handle to the standard output of the current process.
81 ///
82 /// See `std::io::`[`stdout`].
83 pub fn stdout() -> Stdout { stdout() }
84}