git_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 feature = "document-features",
12 cfg_attr(doc, doc = ::document_features::document_features!())
13)]
14#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
15#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
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;
30///
31#[cfg(feature = "zlib")]
32pub mod zlib;
33
34///
35pub mod iter {
36 /// An iterator over chunks of input, producing `Vec<Item>` with a size of `size`, with the last chunk being the remainder and thus
37 /// potentially smaller than `size`.
38 pub struct Chunks<I> {
39 /// The inner iterator to ask for items.
40 pub inner: I,
41 /// The size of chunks to produce
42 pub size: usize,
43 }
44
45 impl<I, Item> Iterator for Chunks<I>
46 where
47 I: Iterator<Item = Item>,
48 {
49 type Item = Vec<Item>;
50
51 fn next(&mut self) -> Option<Self::Item> {
52 let mut res = Vec::with_capacity(self.size);
53 let mut items_left = self.size;
54 for item in &mut self.inner {
55 res.push(item);
56 items_left -= 1;
57 if items_left == 0 {
58 break;
59 }
60 }
61 (!res.is_empty()).then_some(res)
62 }
63 }
64}