| 1 | //! # Netbuf |
| 2 | //! |
| 3 | //! [Documentation](https://docs.rs/netbuf) | |
| 4 | //! [Github](https://github.com/tailhook/netbuf) | |
| 5 | //! [Crate](https://crates.io/crates/netbuf) |
| 6 | //! |
| 7 | //! This module currently includes single `Buf` struct for holding buffers. |
| 8 | //! Comparing to `Vec` class buffer has different allocation policy and has |
| 9 | //! a marker of consumed data (i.e. already processed by protocol parser or |
| 10 | //! already written to socket) |
| 11 | //! |
| 12 | //! The `Buf` is deemed good both for input and output network buffer. |
| 13 | //! |
| 14 | //! It also contains helper methods `read_from` and `write_to` which are used |
| 15 | //! to read and append bytes from stream that implements Read and write bytes |
| 16 | //! from buffer to a stream which implements Write respectively. |
| 17 | //! |
| 18 | //! Note there are basically three ways to fill the buffer: |
| 19 | //! |
| 20 | //! * `Buf::read_from` -- preallocates some chunk and gives it to object |
| 21 | //! implemeting Read |
| 22 | //! * `Write::write` -- writes chunk to buffer assuming more data will follow |
| 23 | //! shortly, i.e. it does large preallocations |
| 24 | //! * `Buf::extend` -- writes chunk to buffer assuming it will not grow in the |
| 25 | //! near perspective, so it allocates minimum chunk to hold the data |
| 26 | //! |
| 27 | //! In other words you should use: |
| 28 | //! |
| 29 | //! * `Buf::read_from` -- to read from the network |
| 30 | //! * `Write::write` -- when you are constructing object directly to the buffer |
| 31 | //! incrementally |
| 32 | //! * `Buf::extend` -- when you put whole object in place and give it to the |
| 33 | //! network code for sending |
| 34 | //! |
| 35 | //! More documentation is found in `Buf` object itself |
| 36 | |
| 37 | #[cfg(test)] extern crate mockstream; |
| 38 | |
| 39 | mod buf; |
| 40 | mod range; |
| 41 | |
| 42 | pub use buf::Buf; |
| 43 | pub use range::RangeArgument; |