netio/lib.rs
1//! Alternative implementation of many functions found in [`std::io`],
2//! but suitable for blocking IO over networks.
3//!
4//! The main reason for this crate is the handling of [`ErrorKind`]`::Interrupted` in
5//! `std::io`.
6//! Except for [`std::io::Read::read`] and [`std::io::Write::write`], almost all functions
7//! will ignore interrupts and just retry.
8//!
9//! This crate provides alternative implementations using a similar API but allow for interrupts
10//! whithout losing any content.
11//!
12//! Most functions are based on buffered readers instead of plain readers to ensure that no
13//! content is lost on retry.
14//!
15//! [`std::io`]: https://doc.rust-lang.org/nightly/std/io/index.html
16//! [`ErrorKind`]: https://doc.rust-lang.org/nightly/std/io/enum.ErrorKind.html
17//! [`std::io::Read::read`]: https://doc.rust-lang.org/nightly/std/io/trait.Read.html#tymethod.read
18//! [`std::io::Write::write`]:
19//! https://doc.rust-lang.org/nightly/std/io/trait.Write.html#tymethod.write
20
21extern crate memchr;
22pub extern crate buf_redux;
23
24mod impls;
25mod adapt;
26mod iter;
27mod utf8;
28mod stream;
29mod read;
30mod write;
31mod bufread;
32mod bufreadgrow;
33mod copy;
34
35pub mod mock;
36
37use buf_redux as br;
38
39pub use stream::Stream;
40pub use read::Read;
41pub use write::Write;
42pub use bufread::BufRead;
43pub use bufreadgrow::BufReadGrow;
44pub use copy::{copy, copy_until};
45pub use adapt::{Retry, Take, Repeat, Chain, Compat};
46pub use iter::{Bytes, Split, Collect};
47pub use utf8::Utf8Reader;
48
49pub use std::io::{Result, Error, ErrorKind};
50
51pub trait IoExt {
52 fn compat(self) -> Compat<Self>
53 where Self: Sized
54 {
55 Compat::new(self)
56 }
57}
58
59impl<T> IoExt for T {}
60
61/// Alternative to `std::io::BufReader`
62pub type BufReader<R> = br::BufReader<R>;