Skip to main content

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(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///
33pub mod iter {
34    /// An iterator over chunks of input, producing `Vec<Item>` with a size of `size`, with the last chunk being the remainder and thus
35    /// potentially smaller than `size`.
36    pub struct Chunks<I> {
37        /// The inner iterator to ask for items.
38        pub inner: I,
39        /// The size of chunks to produce
40        pub size: usize,
41    }
42
43    impl<I, Item> Iterator for Chunks<I>
44    where
45        I: Iterator<Item = Item>,
46    {
47        type Item = Vec<Item>;
48
49        fn next(&mut self) -> Option<Self::Item> {
50            let mut res = Vec::with_capacity(self.size);
51            let mut items_left = self.size;
52            for item in &mut self.inner {
53                res.push(item);
54                items_left -= 1;
55                if items_left == 0 {
56                    break;
57                }
58            }
59            (!res.is_empty()).then_some(res)
60        }
61    }
62}