@@ -68,6 +68,7 @@ pub struct ProgressBar {
6868}
6969
7070impl ProgressBar {
71+
7172 /// Create a `ProgressBar` object to update progress
7273 ///
7374 /// # Arguments
@@ -102,6 +103,12 @@ impl ProgressBar {
102103 } )
103104 }
104105
106+ /// Increment the progress bar by the specified amount and write the progress
107+ ///
108+ /// # Arguments
109+ ///
110+ /// * `delta` - The amount to increment the progress bar by
111+ ///
105112 pub fn increment ( & mut self , delta : u64 ) {
106113 if self . format == ProgressFormat :: None {
107114 return ;
@@ -124,12 +131,26 @@ impl ProgressBar {
124131 }
125132 }
126133
134+ /// Set the resource being operated on and write the progress
135+ ///
136+ /// # Arguments
137+ ///
138+ /// * `name` - The name of the resource being operated on
139+ /// * `resource_type` - The type of the resource being operated on
140+ /// * `result` - The result of the operation
141+ ///
127142 pub fn set_resource ( & mut self , name : & str , resource_type : & str , result : Option < & Value > ) {
128143 self . progress_value . resource_name = Some ( name. to_string ( ) ) ;
129144 self . progress_value . resource_type = Some ( resource_type. to_string ( ) ) ;
130145 self . progress_value . result = result. cloned ( ) ;
131146 }
132147
148+ /// Set the status of the operation and write the progress
149+ ///
150+ /// # Arguments
151+ ///
152+ /// * `status` - The status of the operation
153+ ///
133154 pub fn set_activity ( & mut self , activity : & str ) {
134155 match self . format {
135156 ProgressFormat :: Json => {
@@ -143,17 +164,17 @@ impl ProgressBar {
143164 }
144165 }
145166
167+ /// Set the number of total items to complete
168+ ///
169+ /// # Arguments
170+ ///
171+ /// * `len` - The number of total items to complete
172+ ///
146173 pub fn set_length ( & mut self , len : u64 ) {
147174 match self . format {
148175 ProgressFormat :: Json => {
149176 self . item_count = len;
150- if self . item_count > 0 {
151- self . progress_value . percent_complete = if self . item_position >= self . item_count {
152- 100
153- } else {
154- u8:: try_from ( ( self . item_position * 100 ) / self . item_count ) . unwrap_or ( 100 )
155- } ;
156- }
177+ self . set_percent_complete ( ) ;
157178 } ,
158179 ProgressFormat :: Default => {
159180 self . console_bar . pb_set_length ( len) ;
@@ -162,18 +183,18 @@ impl ProgressBar {
162183 }
163184 }
164185
186+ /// Set the position as progress through the items and write the progress
187+ ///
188+ /// # Arguments
189+ ///
190+ /// * `pos` - The position as progress through the items
191+ ///
165192 pub fn set_position ( & mut self , pos : u64 ) {
166193 match self . format {
167194 ProgressFormat :: Json => {
168195 self . item_position = pos;
169- if self . item_count > 0 {
170- self . progress_value . percent_complete = if self . item_position >= self . item_count {
171- 100
172- } else {
173- u8:: try_from ( ( self . item_position * 100 ) / self . item_count ) . unwrap_or ( 100 )
174- } ;
175- self . write_json ( ) ;
176- }
196+ self . set_percent_complete ( ) ;
197+ self . write_json ( ) ;
177198 } ,
178199 ProgressFormat :: Default => {
179200 self . console_bar . pb_set_position ( pos) ;
@@ -189,4 +210,14 @@ impl ProgressBar {
189210 trace ! ( "{}" , t!( "progress.failedToSerialize" , json = self . progress_value : { : ?} ) ) ;
190211 }
191212 }
213+
214+ fn set_percent_complete ( & mut self ) {
215+ if self . item_count > 0 {
216+ self . progress_value . percent_complete = if self . item_position >= self . item_count {
217+ 100
218+ } else {
219+ u8:: try_from ( ( self . item_position * 100 ) / self . item_count ) . unwrap_or ( 100 )
220+ } ;
221+ }
222+ }
192223}
0 commit comments