Struct rusty_dumb_tools::calculator::DumbCalculator

source ·
pub struct DumbCalculator { /* private fields */ }

Implementations§

source§

impl DumbCalculator

a simple calculator that accepts input keys acting like a real calculator; it may task is the keep track of key presses and turn them into “calculation units”; it uses a crate::calc::DumbCalcProcessor to handle the actual calculation processing

for example:

use rusty_dumb_tools::calculator::DumbCalculator;
let mut calculator = DumbCalculator::new();
calculator.push("1").unwrap();
calculator.push(".").unwrap();
calculator.push("0").unwrap();
calculator.push("2").unwrap();
assert_eq!(calculator.get_display(), "1.02");
calculator.push("*").unwrap();
calculator.push("3").unwrap();
assert_eq!(calculator.get_display(), "3");
calculator.push("=").unwrap();
assert_eq!(calculator.get_display(), "3.06");

for a fuller sample code, please refer to the “calculator” sub-demo of crate::demo::run_demo

source

pub fn new_min() -> Self

create a new DumbCalculator instance with minimum feature (i.e. no undo etc)

source

pub fn new() -> Self

create a new DumbCalculator (with all the default features enabled)

source

pub fn new_with_settings(settings: DumbCalculatorSettings) -> Self

like DumbCalculator::new but with settings

source

pub fn push(&mut self, key: &str) -> Result<(), DumbError>

push a “key input”:

source

pub fn push_chars(&mut self, keys: &str) -> Result<(), DumbError>

like DumbCalculator::push but each characters of the input will be pushed individually one by one

source

pub fn undo(&mut self)

undo the last “key input” done by DumbCalculator::push, if undo is enabled

source

pub fn reset(&mut self)

reset the calculator

source

pub fn get_history(&self) -> Option<&[String]>

get history of the “key input”, if history is enabled

source

pub fn get_history_string(&self, better_symbols: bool) -> Option<String>

like DumbCalculator::get_history but returns a string instead

source

pub fn get_display(&self) -> String

get what to show on the calculator’s display

source

pub fn get_display_sized(&self, result_width: usize) -> String

get what to show on the calculator’s display, but with a fixed display width

source

pub fn get_last_operator(&self) -> Option<String>

source

pub fn count_opened_brackets(&self) -> u16

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.