exercises

Log | Files | Refs | README

lib.rs (1299B)


      1 mod adapters;
      2 mod bridge_pattern;
      3 mod builder;
      4 mod calculator;
      5 mod facade;
      6 mod factory;
      7 mod number;
      8 mod operator;
      9 mod token;
     10 mod utilities;
     11 
     12 pub use operator::{BinaryOperation, Operator};
     13 /// Modules and Crates as Facade Pattern
     14 ///
     15 /// By controlling what a module or crate exports through `pub use` re-exports,
     16 /// you create a curated public API that hides internal complexity.
     17 ///
     18 /// This lib.rs file acts as a facade at the crate level.
     19 pub use utilities::{
     20     CachingExpression, ConsoleLogger, Expression, LoggingExpression, NumberExpression,
     21     TimingExpression,
     22 };
     23 
     24 /// This trait defines all number types across different calculator modes
     25 pub trait NumberToken {
     26     fn value(&self) -> f64;
     27     fn format(&self) -> String;
     28 }
     29 
     30 pub trait OperatorToken {
     31     fn precedence(&self) -> u8;
     32     fn evaluate(&self, args: &[f64]) -> Result<f64, String>;
     33 }
     34 
     35 /// TokenFactory trait that ties everything together. It ensures that tokens
     36 /// created by the factory are always compatible.
     37 pub trait TokenFactory {
     38     /// The associated Number and Operator types are the key to type safety
     39     type Number: NumberToken;
     40     type Operator: OperatorToken;
     41 
     42     fn create_number(&self, s: &str) -> Result<Self::Number, String>;
     43     fn create_operator(&self, s: &str) -> Result<Self::Operator, String>;
     44 }