aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d8509d5..00163b1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,5 @@
+use std::f64::consts::{E, PI};
+
mod input;
pub mod ui;
@@ -61,8 +63,8 @@ enum Function {
RSin, // Sine (radians)
RCos, // Cosing (radians)
RTan, // Tangent (radians)
- Deg, // Convert from radians to degrees.
- Rad, // Convert from degrees to radians.
+ Deg, // Convert from radians to degrees
+ Rad, // Convert from degrees to radians
}
impl Function {
@@ -96,6 +98,30 @@ impl Function {
struct ParseFunctionError(String);
+enum Constant {
+ Pi, // Archimedes’ constant (π)
+ E, // Euler's number (e)
+}
+
+impl Constant {
+ fn parse(s: &str) -> Result<Self, ParseConstantError> {
+ match s {
+ "pi" => Ok(Self::Pi),
+ "e" => Ok(Self::E),
+ _ => Err(ParseConstantError(s.to_string())),
+ }
+ }
+
+ fn value(&self) -> f64 {
+ match self {
+ Self::Pi => PI,
+ Self::E => E,
+ }
+ }
+}
+
+struct ParseConstantError(String);
+
pub enum Signal {
None,
Exit,