HPN

Struct HPN 

Source
pub struct HPN { /* private fields */ }
Expand description

Primary struct backing the HPN engine.

Implementations§

Source§

impl HPN

Source

pub fn clear_tape(&mut self)

Clears the history for this calculator object. Does not alter the stack or memory.

Source

pub fn evaluate(&mut self, line: &str)

Parses and evaluates the given string, applying each change in turn.

use hpn::prelude::*;
let mut hp = HPN::default();
hp.evaluate("4 3 2 1");
println!("{hp}");
// Output:
//  0: [ T:    0.000 | Z:    0.000 | Y:    0.000 | X:    0.000 ]  <- 4
//  1: [ T:    0.000 | Z:    0.000 | Y:    0.000 | X:    4.000 ]  <- 3
//  2: [ T:    0.000 | Z:    0.000 | Y:    4.000 | X:    3.000 ]  <- 2
//  3: [ T:    0.000 | Z:    4.000 | Y:    3.000 | X:    2.000 ]  <- 1
//  4: [ T:    4.000 | Z:    3.000 | Y:    2.000 | X:    1.000 ]
Source

pub fn x(&self) -> &Number

Returns the value of the x register.

assert_eq!(*hp.x(), Number::zero());
Source

pub fn y(&self) -> &Number

Returns the value of the y register.

assert_eq!(*hp.y(), Number::one());
Source

pub fn z(&self) -> &Number

Returns the value of the z register.

let hp = HPN::from("3 2 1 0");
assert_eq!(*hp.z(), Number::from(2));
Source

pub fn t(&self) -> &Number

Returns the value of the t register.

let hp = HPN::from("3 2 1 0");
assert_eq!(*hp.t(), Number::from(3));
Source

pub fn tape(&self) -> impl Iterator<Item = String>

Returns the accumulated history of operations performed in this calculator as a lazy iterator of Strings.

let hp = HPN::from("3 4 7 - +");
hp.tape().for_each(|line| println!("{line}"));
Source

pub fn version() -> String

Yields the version of the crate

Trait Implementations§

Source§

impl Clone for HPN

Source§

fn clone(&self) -> HPN

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HPN

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HPN

Constructs new HPN instance, with emtpy tape and 0 in each register.

use hpn::prelude::*;

let mut hp = HPN::default();
Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for HPN

Displays the current state of the stack.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for HPN

Constructs an HPN instance and evaluates the expression passed.

Source§

fn from(expr: &str) -> Self

Converts to this type from the input type.
Source§

impl From<[BigDecimal; 4]> for HPN

Constructs an HPN instance with the given initial stack.

Source§

fn from(stack: [Number; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<[f64; 4]> for HPN

Constructs an HPN instance with the given initial stack.

Source§

fn from(values: [f64; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<[i32; 4]> for HPN

Constructs an HPN instance with the given initial stack.

Source§

fn from(values: [i32; 4]) -> Self

Converts to this type from the input type.
Source§

impl TryFrom<&HPN> for [f64; 4]

Attempts to convert an HPN instance to an [f64; 4].

Source§

type Error = &'static str

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

fn try_from(hp: &HPN) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&HPN> for [i32; 4]

Attempts to convert an HPN instance to an [i32; 4].

Source§

type Error = &'static str

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

fn try_from(hp: &HPN) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for HPN

§

impl RefUnwindSafe for HPN

§

impl Send for HPN

§

impl Sync for HPN

§

impl Unpin for HPN

§

impl UnwindSafe for HPN

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V