summaryrefslogtreecommitdiffstats
path: root/asyncgit/src/progress.rs
diff options
context:
space:
mode:
Diffstat (limited to 'asyncgit/src/progress.rs')
-rw-r--r--asyncgit/src/progress.rs66
1 files changed, 33 insertions, 33 deletions
diff --git a/asyncgit/src/progress.rs b/asyncgit/src/progress.rs
index 55ae92c0..3c58918c 100644
--- a/asyncgit/src/progress.rs
+++ b/asyncgit/src/progress.rs
@@ -6,49 +6,49 @@ use std::cmp;
///
#[derive(Clone, Debug)]
pub struct ProgressPercent {
- /// percent 0..100
- pub progress: u8,
+ /// percent 0..100
+ pub progress: u8,
}
impl ProgressPercent {
- ///
- pub fn new(current: usize, total: usize) -> Self {
- let total = f64::conv(cmp::max(current, total));
- let progress = f64::conv(current) / total * 100.0;
- let progress = u8::try_conv_nearest(progress).unwrap_or(100);
- Self { progress }
- }
- ///
- pub const fn empty() -> Self {
- Self { progress: 0 }
- }
- ///
- pub const fn full() -> Self {
- Self { progress: 100 }
- }
+ ///
+ pub fn new(current: usize, total: usize) -> Self {
+ let total = f64::conv(cmp::max(current, total));
+ let progress = f64::conv(current) / total * 100.0;
+ let progress = u8::try_conv_nearest(progress).unwrap_or(100);
+ Self { progress }
+ }
+ ///
+ pub const fn empty() -> Self {
+ Self { progress: 0 }
+ }
+ ///
+ pub const fn full() -> Self {
+ Self { progress: 100 }
+ }
}
#[cfg(test)]
mod tests {
- use super::*;
+ use super::*;
- #[test]
- fn test_progress_zero_total() {
- let prog = ProgressPercent::new(1, 0);
+ #[test]
+ fn test_progress_zero_total() {
+ let prog = ProgressPercent::new(1, 0);
- assert_eq!(prog.progress, 100);
- }
+ assert_eq!(prog.progress, 100);
+ }
- #[test]
- fn test_progress_zero_all() {
- let prog = ProgressPercent::new(0, 0);
- assert_eq!(prog.progress, 100);
- }
+ #[test]
+ fn test_progress_zero_all() {
+ let prog = ProgressPercent::new(0, 0);
+ assert_eq!(prog.progress, 100);
+ }
- #[test]
- fn test_progress_rounding() {
- let prog = ProgressPercent::new(2, 10);
+ #[test]
+ fn test_progress_rounding() {
+ let prog = ProgressPercent::new(2, 10);
- assert_eq!(prog.progress, 20);
- }
+ assert_eq!(prog.progress, 20);
+ }
}