gix_utils/lib.rs
1//! Utilities shared by the `gitoxide` crates.
2//!
3//! Utilities requiring additional dependencies are available through feature toggles.
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//! ## Feature Flags
20#![cfg_attr(all(doc, feature = "document-features"), doc = ::document_features::document_features!())]
21#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg))]
22#![deny(missing_docs)]
23#![forbid(unsafe_code)]
24
25/// Cache efficiency diagnostics, enabled with `cache-efficiency-debug`.
26pub mod cache;
27/// Variable-length integer decoding.
28pub mod decode;
29#[cfg(feature = "interrupt")]
30pub mod interrupt;
31#[cfg(feature = "io-pipe")]
32pub mod io;
33pub mod iter;
34#[cfg(feature = "progress")]
35pub mod progress;
36
37///
38pub mod backoff;
39
40///
41pub mod rng;
42
43///
44pub mod buffers;
45
46///
47pub mod str;
48
49///
50pub mod btoi;
51
52/// Byte-string conversion utilities.
53#[cfg(feature = "bstr")]
54mod bstr;
55#[cfg(feature = "bstr")]
56pub use bstr::{AsBStr, AsBStrOpt};
57
58/// Return whether `byte` is whitespace according to Git's locale-independent `sane_ctype` table.
59///
60/// This includes space, horizontal tab, newline and carriage return, but excludes vertical tab and form feed.
61#[inline]
62pub const fn git_is_space(byte: u8) -> bool {
63 matches!(byte, b' ' | b'\t' | b'\n' | b'\r')
64}
65
66/// A utility to do buffer-swapping with.
67///
68/// Use `src` to read from and `dest` to write to, and after actually changing data, call [Buffers::swap()].
69/// To be able to repeat the process, this time using what was `dest` as `src`, freeing up `dest` for writing once more.
70///
71/// Note that after each [`Buffers::swap()`], `src` is the most recent version of the data, just like before each swap.
72#[derive(Default, Clone)]
73pub struct Buffers {
74 /// The source data, as basis for processing.
75 pub src: Vec<u8>,
76 /// The data produced after processing `src`.
77 pub dest: Vec<u8>,
78}