Debian Codegraph @

src/progress.rs

raw symbols SCIP
1 //! Various `prodash` types along with various utilities for comfort.
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
3
4 #[cfg(feature = "progress-unit-bytes")]
5 pub use bytesizerust-analyzer cargo bytesize 2.3.1 crate/;
6 pub use prodashrust-analyzer cargo prodash 28.0.0 crate/::{
7 selfrust-analyzer cargo prodash 28.0.0 crate/,
8 messagesrust-analyzer cargo prodash 28.0.0 messages/::MessageLevelrust-analyzer cargo prodash 28.0.0 messages/MessageLevel#,
9 progressrust-analyzer cargo prodash 28.0.0 progress/::{
10 AtomicSteprust-analyzer cargo prodash 28.0.0 progress/AtomicStep#, Discardrust-analyzer cargo prodash 28.0.0 progress/utils/Discard#, DoOrDiscardrust-analyzer cargo prodash 28.0.0 progress/utils/DoOrDiscard#, Eitherrust-analyzer cargo prodash 28.0.0 progress/utils/Either#, Idrust-analyzer cargo prodash 28.0.0 progress/Id#, Steprust-analyzer cargo prodash 28.0.0 progress/Step#, StepSharedrust-analyzer cargo prodash 28.0.0 progress/StepShared#, Taskrust-analyzer cargo prodash 28.0.0 progress/Task#, ThroughputOnDroprust-analyzer cargo prodash 28.0.0 progress/utils/ThroughputOnDrop#, Valuerust-analyzer cargo prodash 28.0.0 progress/Value#, UNKNOWNrust-analyzer cargo prodash 28.0.0 progress/UNKNOWN.,
11 },
12 unitrust-analyzer cargo prodash 28.0.0 unit/, BoxedDynNestedProgressrust-analyzer cargo prodash 28.0.0 traits/BoxedDynNestedProgress#, Countrust-analyzer cargo prodash 28.0.0 traits/Count#, DynNestedProgressrust-analyzer cargo prodash 28.0.0 traits/DynNestedProgress#, DynNestedProgressToNestedProgressrust-analyzer cargo prodash 28.0.0 traits/DynNestedProgressToNestedProgress#, NestedProgressrust-analyzer cargo prodash 28.0.0 traits/NestedProgress#,
13 Progressrust-analyzer cargo prodash 28.0.0 traits/Progress#, Unitrust-analyzer cargo prodash 28.0.0 unit/Unit#,
14 };
15 /// A stub for the portions of the `bytesize` crate that we use internally in `gitoxide`.
16 #[cfg(not(feature = "progress-unit-bytes"))]
17 pub mod bytesize {
18 /// A stub for the `ByteSize` wrapper.
19 pub struct ByteSize(pub u64);
20
21 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ByteSize {
22 fn fmt(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
23 selfrust-analyzer cargo gix-features 0.48.0 progress/.0.fmt(f)
24 }
25 }
26 }
27
28 /// A unit for displaying bytes with throughput and progress percentage.
29 #[cfg(feature = "progress-unit-bytes")]
30 pub fn bytesrust-analyzer cargo gix-features 0.48.0 progress/bytes().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Unitrust-analyzer cargo prodash 28.0.0 unit/Unit#> {
31 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unitrust-analyzer cargo prodash 28.0.0 unit/::dynamic_and_moderust-analyzer cargo prodash 28.0.0 unit/dynamic_and_mode().(
32 unitrust-analyzer cargo prodash 28.0.0 unit/::Bytesrust-analyzer cargo prodash 28.0.0 unit/bytes/Bytes#,
33 unitrust-analyzer cargo prodash 28.0.0 unit/::displayrust-analyzer cargo prodash 28.0.0 unit/display/::Moderust-analyzer cargo prodash 28.0.0 unit/display/Mode#::with_throughputrust-analyzer cargo prodash 28.0.0 unit/display/impl#[Mode]with_throughput().().and_percentagerust-analyzer cargo prodash 28.0.0 unit/display/impl#[Mode]and_percentage().(),
34 ))
35 }
36
37 /// A unit for displaying bytes with throughput and progress percentage.
38 #[cfg(not(feature = "progress-unit-bytes"))]
39 pub fn bytes() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Unitrust-analyzer cargo prodash 28.0.0 unit/Unit#> {
40 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unitrust-analyzer cargo prodash 28.0.0 unit/::label_and_moderust-analyzer cargo prodash 28.0.0 unit/label_and_mode().(
41 "B",
42 unitrust-analyzer cargo prodash 28.0.0 unit/::displayrust-analyzer cargo prodash 28.0.0 unit/display/::Moderust-analyzer cargo prodash 28.0.0 unit/display/Mode#::with_throughput().and_percentage(),
43 ))
44 }
45
46 /// A unit for displaying human readable numbers with throughput and progress percentage, and a single decimal place.
47 pub fn countrust-analyzer cargo gix-features 0.48.0 progress/count().(name: &'static str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Unitrust-analyzer cargo prodash 28.0.0 unit/Unit#> {
48 count_with_decimalsrust-analyzer cargo gix-features 0.48.0 progress/count_with_decimals().(name, 1)
49 }
50
51 /// A unit for displaying human readable numbers with `name` suffix,
52 /// with throughput and progress percentage, and `decimals` decimal places.
53 #[cfg(feature = "progress-unit-human-numbers")]
54 pub fn count_with_decimalsrust-analyzer cargo gix-features 0.48.0 progress/count_with_decimals().(name: &'static str, decimals: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Unitrust-analyzer cargo prodash 28.0.0 unit/Unit#> {
55 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unitrust-analyzer cargo prodash 28.0.0 unit/::dynamic_and_moderust-analyzer cargo prodash 28.0.0 unit/dynamic_and_mode().(
56 unitrust-analyzer cargo prodash 28.0.0 unit/::Humanrust-analyzer cargo prodash 28.0.0 unit/human/Human#::newrust-analyzer cargo prodash 28.0.0 unit/human/impl#[Human]new().(
57 {
58 let mut f = unitrust-analyzer cargo prodash 28.0.0 unit/::humanrust-analyzer cargo prodash 28.0.0 unit/human/::Formatterrust-analyzer cargo human_format 1.2.1 Formatter#::newrust-analyzer cargo human_format 1.2.1 impl#[Formatter]new().();
59 f.with_decimalsrust-analyzer cargo human_format 1.2.1 impl#[Formatter]with_decimals().(decimals);
60 f
61 },
62 name,
63 ),
64 unitrust-analyzer cargo prodash 28.0.0 unit/::displayrust-analyzer cargo prodash 28.0.0 unit/display/::Moderust-analyzer cargo prodash 28.0.0 unit/display/Mode#::with_throughputrust-analyzer cargo prodash 28.0.0 unit/display/impl#[Mode]with_throughput().().and_percentagerust-analyzer cargo prodash 28.0.0 unit/display/impl#[Mode]and_percentage().(),
65 ))
66 }
67
68 /// A unit for displaying human readable numbers with `name` suffix,
69 /// with throughput and progress percentage, and `decimals` decimal places.
70 #[cfg(not(feature = "progress-unit-human-numbers"))]
71 pub fn count_with_decimals(name: &'static str, _decimals: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Unitrust-analyzer cargo prodash 28.0.0 unit/Unit#> {
72 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unitrust-analyzer cargo prodash 28.0.0 unit/::label_and_moderust-analyzer cargo prodash 28.0.0 unit/label_and_mode().(
73 name,
74 unitrust-analyzer cargo prodash 28.0.0 unit/::displayrust-analyzer cargo prodash 28.0.0 unit/display/::Moderust-analyzer cargo prodash 28.0.0 unit/display/Mode#::with_throughput().and_percentage(),
75 ))
76 }
77
78 /// A predefined unit for displaying a multi-step progress
79 pub fn stepsrust-analyzer cargo gix-features 0.48.0 progress/steps().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Unitrust-analyzer cargo prodash 28.0.0 unit/Unit#> {
80 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unitrust-analyzer cargo prodash 28.0.0 unit/::dynamicrust-analyzer cargo prodash 28.0.0 unit/dynamic().(unitrust-analyzer cargo prodash 28.0.0 unit/::Rangerust-analyzer cargo prodash 28.0.0 unit/range/Range#::newrust-analyzer cargo prodash 28.0.0 unit/range/impl#[Range]new().("steps")))
81 }
82
83 /// A structure passing every [`read`](std::io::Read::read()) call through to the contained Progress instance using [`inc_by(bytes_read)`](Count::inc_by()).
84 pub struct Readrust-analyzer cargo gix-features 0.48.0 progress/Read#<T, P> {
85 /// The implementor of [`std::io::Read`] to which progress is added
86 pub innerrust-analyzer cargo gix-features 0.48.0 progress/Read#inner.: T,
87 /// The progress instance receiving progress information on each invocation of `reader`
88 pub progressrust-analyzer cargo gix-features 0.48.0 progress/Read#progress.: P,
89 }
90
91 impl<T, P> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for Readrust-analyzer cargo gix-features 0.48.0 progress/Read#<T, P>
92 where
93 T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#,
94 P: Progressrust-analyzer cargo prodash 28.0.0 traits/Progress#,
95 {
96 fn readrust-analyzer cargo gix-features 0.48.0 progress/impl#[`Read<T, P>`][Read]read().(&mut self, buf: &mut [u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
97 let bytes_read = self.innerrust-analyzer cargo gix-features 0.48.0 progress/Read#inner..readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read().(buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
98 self.progressrust-analyzer cargo gix-features 0.48.0 progress/Read#progress..inc_byrust-analyzer cargo prodash 28.0.0 traits/Count#inc_by().(bytes_read);
99 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes_read)
100 }
101 }
102
103 impl<T, P> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead# for Readrust-analyzer cargo gix-features 0.48.0 progress/Read#<T, P>
104 where
105 T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#,
106 P: Progressrust-analyzer cargo prodash 28.0.0 traits/Progress#,
107 {
108 fn fill_bufrust-analyzer cargo gix-features 0.48.0 progress/impl#[`Read<T, P>`][BufRead]fill_buf().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&[u8]> {
109 self.innerrust-analyzer cargo gix-features 0.48.0 progress/Read#inner..fill_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#fill_buf().()
110 }
111
112 fn consumerust-analyzer cargo gix-features 0.48.0 progress/impl#[`Read<T, P>`][BufRead]consume().(&mut self, amt: usize) {
113 self.innerrust-analyzer cargo gix-features 0.48.0 progress/Read#inner..consumerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#consume().(amt);
114 }
115 }
116
117 /// A structure passing every [`write`][std::io::Write::write()] call through to the contained Progress instance using [`inc_by(bytes_written)`](Count::inc_by()).
118 ///
119 /// This is particularly useful if the final size of the bytes to write is known or can be estimated precisely enough.
120 pub struct Writerust-analyzer cargo gix-features 0.48.0 progress/Write#<T, P> {
121 /// The implementor of [`std::io::Write`] to which progress is added
122 pub innerrust-analyzer cargo gix-features 0.48.0 progress/Write#inner.: T,
123 /// The progress instance receiving progress information on each invocation of `reader`
124 pub progressrust-analyzer cargo gix-features 0.48.0 progress/Write#progress.: P,
125 }
126
127 impl<T, P> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for Writerust-analyzer cargo gix-features 0.48.0 progress/Write#<T, P>
128 where
129 T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#,
130 P: Progressrust-analyzer cargo prodash 28.0.0 traits/Progress#,
131 {
132 fn writerust-analyzer cargo gix-features 0.48.0 progress/impl#[`Write<T, P>`][Write]write().(&mut self, buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
133 let written = self.innerrust-analyzer cargo gix-features 0.48.0 progress/Write#inner..writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write().(buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
134 self.progressrust-analyzer cargo gix-features 0.48.0 progress/Write#progress..inc_byrust-analyzer cargo prodash 28.0.0 traits/Count#inc_by().(written);
135 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(written)
136 }
137
138 fn flushrust-analyzer cargo gix-features 0.48.0 progress/impl#[`Write<T, P>`][Write]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
139 self.innerrust-analyzer cargo gix-features 0.48.0 progress/Write#inner..flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()
140 }
141 }
142
143 impl<T, P> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek# for Writerust-analyzer cargo gix-features 0.48.0 progress/Write#<T, P>
144 where
145 T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#,
146 {
147 fn seekrust-analyzer cargo gix-features 0.48.0 progress/impl#[`Write<T, P>`][Seek]seek().(&mut self, pos: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u64> {
148 self.innerrust-analyzer cargo gix-features 0.48.0 progress/Write#inner..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#seek().(pos)
149 }
150 }