Cargo fmt
This commit is contained in:
parent
4d1badc36b
commit
0d67e393c1
34
src/calc.rs
34
src/calc.rs
@ -262,28 +262,46 @@ impl Calculator {
|
|||||||
'r' => self.angle_mode = CalculatorAngleMode::Radians,
|
'r' => self.angle_mode = CalculatorAngleMode::Radians,
|
||||||
'g' => self.angle_mode = CalculatorAngleMode::Grads,
|
'g' => self.angle_mode = CalculatorAngleMode::Grads,
|
||||||
'_' => self.display_mode = CalculatorDisplayMode::Default,
|
'_' => self.display_mode = CalculatorDisplayMode::Default,
|
||||||
',' => self.display_mode = CalculatorDisplayMode::Separated{separator: ','},
|
',' => self.display_mode = CalculatorDisplayMode::Separated { separator: ',' },
|
||||||
' ' => self.display_mode = CalculatorDisplayMode::Separated{separator: ' '},
|
' ' => self.display_mode = CalculatorDisplayMode::Separated { separator: ' ' },
|
||||||
's' => self.display_mode = CalculatorDisplayMode::Scientific{precision: DEFAULT_PRECISION},
|
's' => {
|
||||||
|
self.display_mode = CalculatorDisplayMode::Scientific {
|
||||||
|
precision: DEFAULT_PRECISION,
|
||||||
|
}
|
||||||
|
}
|
||||||
'S' => {
|
'S' => {
|
||||||
let precision = self.checked_get(0)? as usize;
|
let precision = self.checked_get(0)? as usize;
|
||||||
if precision > MAX_PRECISION {
|
if precision > MAX_PRECISION {
|
||||||
return Err(CalculatorError::PrecisionTooHigh);
|
return Err(CalculatorError::PrecisionTooHigh);
|
||||||
}
|
}
|
||||||
self.display_mode = CalculatorDisplayMode::Scientific{precision: self.pop_usize()?}
|
self.display_mode = CalculatorDisplayMode::Scientific {
|
||||||
|
precision: self.pop_usize()?,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
'e' => {
|
'e' => {
|
||||||
self.display_mode = CalculatorDisplayMode::Engineering{precision: DEFAULT_PRECISION}
|
self.display_mode = CalculatorDisplayMode::Engineering {
|
||||||
|
precision: DEFAULT_PRECISION,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
'E' => {
|
'E' => {
|
||||||
let precision = self.checked_get(0)? as usize;
|
let precision = self.checked_get(0)? as usize;
|
||||||
if precision > MAX_PRECISION {
|
if precision > MAX_PRECISION {
|
||||||
return Err(CalculatorError::PrecisionTooHigh);
|
return Err(CalculatorError::PrecisionTooHigh);
|
||||||
}
|
}
|
||||||
self.display_mode = CalculatorDisplayMode::Engineering{precision: self.pop_usize()?}
|
self.display_mode = CalculatorDisplayMode::Engineering {
|
||||||
|
precision: self.pop_usize()?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'f' => {
|
||||||
|
self.display_mode = CalculatorDisplayMode::Fixed {
|
||||||
|
precision: DEFAULT_PRECISION,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'F' => {
|
||||||
|
self.display_mode = CalculatorDisplayMode::Fixed {
|
||||||
|
precision: self.pop_usize()?,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
'f' => self.display_mode = CalculatorDisplayMode::Fixed{precision: DEFAULT_PRECISION},
|
|
||||||
'F' => self.display_mode = CalculatorDisplayMode::Fixed{precision: self.pop_usize()?},
|
|
||||||
_ => return Err(CalculatorError::NoSuchSetting(c)),
|
_ => return Err(CalculatorError::NoSuchSetting(c)),
|
||||||
};
|
};
|
||||||
self.state = CalculatorState::Normal;
|
self.state = CalculatorState::Normal;
|
||||||
|
@ -76,7 +76,7 @@ impl fmt::Display for CalculatorAngleMode {
|
|||||||
// Could also have added content="precision"
|
// Could also have added content="precision"
|
||||||
pub enum CalculatorDisplayMode {
|
pub enum CalculatorDisplayMode {
|
||||||
Default,
|
Default,
|
||||||
Separated { separator: char },
|
Separated { separator: char },
|
||||||
Scientific { precision: usize },
|
Scientific { precision: usize },
|
||||||
Engineering { precision: usize },
|
Engineering { precision: usize },
|
||||||
Fixed { precision: usize },
|
Fixed { precision: usize },
|
||||||
@ -86,10 +86,10 @@ impl fmt::Display for CalculatorDisplayMode {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
CalculatorDisplayMode::Default => write!(f, "DEF"),
|
CalculatorDisplayMode::Default => write!(f, "DEF"),
|
||||||
CalculatorDisplayMode::Separated{separator} => write!(f, "SEP({})", separator),
|
CalculatorDisplayMode::Separated { separator } => write!(f, "SEP({})", separator),
|
||||||
CalculatorDisplayMode::Scientific{precision} => write!(f, "SCI({})", precision),
|
CalculatorDisplayMode::Scientific { precision } => write!(f, "SCI({})", precision),
|
||||||
CalculatorDisplayMode::Engineering{precision} => write!(f, "ENG({})", precision),
|
CalculatorDisplayMode::Engineering { precision } => write!(f, "ENG({})", precision),
|
||||||
CalculatorDisplayMode::Fixed{precision} => write!(f, "FIX({})", precision),
|
CalculatorDisplayMode::Fixed { precision } => write!(f, "FIX({})", precision),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,14 @@ impl fmt::Display for CalculatorError {
|
|||||||
CalculatorError::ParseError => write!(f, "Parse error"),
|
CalculatorError::ParseError => write!(f, "Parse error"),
|
||||||
CalculatorError::PrecisionTooHigh => write!(f, "Precision too high"),
|
CalculatorError::PrecisionTooHigh => write!(f, "Precision too high"),
|
||||||
CalculatorError::SaveError(None) => write!(f, "Could not save"),
|
CalculatorError::SaveError(None) => write!(f, "Could not save"),
|
||||||
CalculatorError::SaveError(Some(ConfyError::SerializeTomlError(e))) => write!(f, "Save serialization error: {}", e),
|
CalculatorError::SaveError(Some(ConfyError::SerializeTomlError(e))) => {
|
||||||
|
write!(f, "Save serialization error: {}", e)
|
||||||
|
}
|
||||||
CalculatorError::SaveError(Some(e)) => write!(f, "Could not save: {}", e),
|
CalculatorError::SaveError(Some(e)) => write!(f, "Could not save: {}", e),
|
||||||
CalculatorError::LoadError(None) => write!(f, "Could not load"),
|
CalculatorError::LoadError(None) => write!(f, "Could not load"),
|
||||||
CalculatorError::LoadError(Some(ConfyError::SerializeTomlError(e))) => write!(f, "Load serialization error: {}", e),
|
CalculatorError::LoadError(Some(ConfyError::SerializeTomlError(e))) => {
|
||||||
|
write!(f, "Load serialization error: {}", e)
|
||||||
|
}
|
||||||
CalculatorError::LoadError(Some(e)) => write!(f, "Could not load: {}", e),
|
CalculatorError::LoadError(Some(e)) => write!(f, "Could not load: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,16 +119,16 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let content = vec![Spans::from(Span::raw(
|
let content = vec![Spans::from(Span::raw(
|
||||||
match app.calculator.get_display_mode() {
|
match app.calculator.get_display_mode() {
|
||||||
CalculatorDisplayMode::Default => format!("{:>2}: {}", i, *m),
|
CalculatorDisplayMode::Default => format!("{:>2}: {}", i, *m),
|
||||||
CalculatorDisplayMode::Separated{separator} => {
|
CalculatorDisplayMode::Separated { separator } => {
|
||||||
format!("{:>2}: {}", i, fmt_separated(*m, *separator))
|
format!("{:>2}: {}", i, fmt_separated(*m, *separator))
|
||||||
}
|
}
|
||||||
CalculatorDisplayMode::Scientific{precision} => {
|
CalculatorDisplayMode::Scientific { precision } => {
|
||||||
format!("{:>2}: {}", i, fmt_scientific(*m, *precision))
|
format!("{:>2}: {}", i, fmt_scientific(*m, *precision))
|
||||||
}
|
}
|
||||||
CalculatorDisplayMode::Engineering{precision} => {
|
CalculatorDisplayMode::Engineering { precision } => {
|
||||||
format!("{:>2}: {}", i, fmt_engineering(*m, *precision))
|
format!("{:>2}: {}", i, fmt_engineering(*m, *precision))
|
||||||
}
|
}
|
||||||
CalculatorDisplayMode::Fixed{precision} => {
|
CalculatorDisplayMode::Fixed { precision } => {
|
||||||
format!("{:>2}: {:.precision$}", i, m, precision = precision)
|
format!("{:>2}: {:.precision$}", i, m, precision = precision)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user