@@ -6,6 +6,8 @@ use ui_sys::{self, uiControl, uiProgressBar};
66/// An enum representing the value of a `ProgressBar`
77pub enum ProgressBarValue {
88 /// Represents a set, consistent percentage of the bar to be filled
9+ ///
10+ /// The u32 should be in the range 0..=100
911 Determinate ( u32 ) ,
1012 /// Represents an indeterminate value of the progress bar, useful
1113 /// if you don't know how much of the task being represented is completed
@@ -38,6 +40,10 @@ impl ProgressBar {
3840 }
3941
4042 /// Set the value of the progress bar to a determinate value
43+ ///
44+ /// # Panics
45+ ///
46+ /// This function will panic if `value` is not in the range 0..=100
4147 pub fn set_determinate ( & mut self , value : u32 ) {
4248 self . set_value ( ProgressBarValue :: Determinate ( value) ) ;
4349 }
@@ -48,9 +54,20 @@ impl ProgressBar {
4854 }
4955
5056 /// Set the value of the progress bar
57+ ///
58+ /// # Panics
59+ ///
60+ /// This function will panic if the value is `Determinate` and its value is not
61+ /// in the range 0..=100
5162 pub fn set_value ( & mut self , value : ProgressBarValue ) {
5263 let sys_value = match value {
53- ProgressBarValue :: Determinate ( value) => value as i32 ,
64+ ProgressBarValue :: Determinate ( value) => {
65+ assert ! ( match value {
66+ 0 ..=100 => true ,
67+ _ => false ,
68+ } ) ;
69+ value as i32
70+ }
5471 ProgressBarValue :: Indeterminate => -1 ,
5572 } ;
5673 unsafe { ui_sys:: uiProgressBarSetValue ( self . uiProgressBar , sys_value) }
0 commit comments