| 1 | //! A crate with utilities that don't need feature toggles. |
| 2 | //! |
| 3 | //! If they would need feature toggles, they should be in `gix-features` instead. |
| 4 | //! |
| 5 | //! ## Examples |
| 6 | //! |
| 7 | //! ``` |
| 8 | //! use std::time::Duration; |
| 9 | //! |
| 10 | //! use gix_utils::{backoff::Quadratic}; |
| 11 | //! |
| 12 | //! let waits: Vec<_> = Quadratic::default().take(3).collect(); |
| 13 | //! assert_eq!(waits, vec![ |
| 14 | //! Duration::from_millis(1), |
| 15 | //! Duration::from_millis(4), |
| 16 | //! Duration::from_millis(9), |
| 17 | //! ]); |
| 18 | //! ``` |
| 19 | #![deny(missing_docs)] |
| 20 | #![forbid(unsafe_code)] |
| 21 | |
| 22 | /// |
| 23 | pub mod backoff; |
| 24 | |
| 25 | /// |
| 26 | pub mod rng; |
| 27 | |
| 28 | /// |
| 29 | pub mod buffers; |
| 30 | |
| 31 | /// |
| 32 | pub mod str; |
| 33 | |
| 34 | /// |
| 35 | pub mod btoi; |
| 36 | |
| 37 | /// Byte-string conversion utilities. |
| 38 | #[cfg(feature = "bstr")] |
| 39 | mod bstr; |
| 40 | #[cfg(feature = "bstr")] |
| 41 | pub use bstr::{AsBStr, AsBStrOpt}; |
| 42 | |
| 43 | /// A utility to do buffer-swapping with. |
| 44 | /// |
| 45 | /// Use `src` to read from and `dest` to write to, and after actually changing data, call [Buffers::swap()]. |
| 46 | /// To be able to repeat the process, this time using what was `dest` as `src`, freeing up `dest` for writing once more. |
| 47 | /// |
| 48 | /// Note that after each [`Buffers::swap()`], `src` is the most recent version of the data, just like before each swap. |
| 49 | #[derive(Default, Clone)] |
| 50 | pub struct Buffers { |
| 51 | /// The source data, as basis for processing. |
| 52 | pub src: Vec<u8>, |
| 53 | /// The data produced after processing `src`. |
| 54 | pub dest: Vec<u8>, |
| 55 | } |