gix_features/lib.rs
1//! A crate providing foundational capabilities to other `git-*` crates with trade-offs between compile time, binary size or speed
2//! selectable using cargo feature toggles.
3//!
4//! It's designed to allow the application level crate to configure feature toggles, affecting all other `git-*` crates using
5//! this one.
6//!
7//! Thus all features provided here commonly have a 'cheap' base implementation, with the option to pull in
8//! counterparts with higher performance.
9//! ## Feature Flags
10#![cfg_attr(
11 all(doc, feature = "document-features"),
12 doc = ::document_features::document_features!()
13)]
14#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg))]
15#![deny(rust_2018_idioms, missing_docs)]
16
17///
18pub mod cache;
19///
20pub mod decode;
21pub mod fs;
22pub mod hash;
23pub mod interrupt;
24#[cfg(feature = "io-pipe")]
25pub mod io;
26pub mod parallel;
27#[cfg(feature = "progress")]
28pub mod progress;
29pub mod threading;
30pub use gix_trace as trace;
31
32///
33#[cfg(feature = "zlib")]
34pub mod zlib;
35
36///
37pub mod iter {
38 /// An iterator over chunks of input, producing `Vec<Item>` with a size of `size`, with the last chunk being the remainder and thus
39 /// potentially smaller than `size`.
40 pub struct Chunks<I> {
41 /// The inner iterator to ask for items.
42 pub inner: I,
43 /// The size of chunks to produce
44 pub size: usize,
45 }
46
47 impl<I, Item> Iterator for Chunks<I>
48 where
49 I: Iterator<Item = Item>,
50 {
51 type Item = Vec<Item>;
52
53 fn next(&mut self) -> Option<Self::Item> {
54 let mut res = Vec::with_capacity(self.size);
55 let mut items_left = self.size;
56 for item in &mut self.inner {
57 res.push(item);
58 items_left -= 1;
59 if items_left == 0 {
60 break;
61 }
62 }
63 (!res.is_empty()).then_some(res)
64 }
65 }
66}