calc_rational

CLI calculator for rational numbers.
git clone https://git.philomathiclife.com/repos/calc_rational
Log | Files | Refs | README

commit a22c03483af9d215ab92df81c0312b2d08fff2c9
parent 722270dd68724047fa8ef31a80783af76a4eddea
Author: Zack Newman <zack@philomathiclife.com>
Date:   Mon, 28 Aug 2023 18:09:21 -0600

small edits to docs. update deps.

Diffstat:
MCargo.toml | 6+++---
MREADME.md | 4++--
Msrc/cache.rs | 3++-
Msrc/lending_iterator.rs | 1+
Msrc/lib.rs | 31+++++++++++++++++--------------
Msrc/main.rs | 6++++--
6 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" name = "calc_rational" readme = "README.md" repository = "https://git.philomathiclife.com/repos/calc_rational/" -version = "0.5.1" +version = "0.5.2" [lib] name = "calc_lib" @@ -20,11 +20,11 @@ name = "calc" path = "src/main.rs" [dependencies] -num-bigint = { version = "0.4.3", default-features = false } +num-bigint = { version = "0.4.4", default-features = false } num-integer = { version = "0.1.45", default-features = false } num-rational = { version = "0.4.1", default-features = false, features = ["num-bigint"] } num-traits = { version = "0.2.16", default-features = false } -priv_sep = { version = "0.3.0", default-features = false, features = ["openbsd"], optional = true } +priv_sep = { version = "0.4.1", default-features = false, features = ["openbsd"], optional = true } rand = { version = "0.8.5", default-features = false, features = ["std", "std_rng"], optional = true } [build-dependencies] diff --git a/README.md b/README.md @@ -107,7 +107,7 @@ be displayed if called incorrectly. ## Rand expression -`rand(expression, expression)` generates a random 64-integer inclusively between the passed expressions. +`rand(expression, expression)` generates a random 64-bit integer inclusively between the passed expressions. An error will be displayed if called incorrectly. `rand()` generates a random 64-bit integer. ## Numbers @@ -238,7 +238,7 @@ Cloning into 'calc_rational'... Compiling num-bigint v0.4.3 Compiling num-rational v0.4.1 Compiling rustc_version v0.4.0 - Compiling priv_sep v0.2.0 + Compiling priv_sep v0.3.0 Compiling calc_rational v0.5.1 (/home/zack/calc_rational) Compiling getrandom v0.2.10 Compiling rand_core v0.6.4 diff --git a/src/cache.rs b/src/cache.rs @@ -16,7 +16,8 @@ #![allow( clippy::arithmetic_side_effects, clippy::blanket_clippy_restriction_lints, - clippy::implicit_return + clippy::implicit_return, + clippy::min_ident_chars )] use core::ops::Index; /// A cache of `N` `T`s. When the cache is filled up, diff --git a/src/lending_iterator.rs b/src/lending_iterator.rs @@ -17,6 +17,7 @@ clippy::arithmetic_side_effects, clippy::blanket_clippy_restriction_lints, clippy::implicit_return, + clippy::min_ident_chars, clippy::missing_trait_methods, clippy::question_mark_used, clippy::single_char_lifetime_names diff --git a/src/lib.rs b/src/lib.rs @@ -54,7 +54,7 @@ //! //! ## Rand expression //! -//! `rand(expression, expression)` generates a random 64-integer inclusively between the passed expressions. +//! `rand(expression, expression)` generates a random 64-bit integer inclusively between the passed expressions. //! An error will be displayed if called incorrectly. `rand()` generates a random 64-bit integer. //! //! ## Numbers @@ -129,9 +129,11 @@ clippy::blanket_clippy_restriction_lints, clippy::implicit_return, clippy::into_iter_on_ref, + clippy::min_ident_chars, clippy::missing_trait_methods, clippy::question_mark_used, clippy::ref_patterns, + clippy::single_call_fn, clippy::single_char_lifetime_names, clippy::unseparated_literal_suffix )] @@ -437,7 +439,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> }; self.consume_ws(); let Some(b) = self.utf8.get(self.i) else { - return Ok(Empty(self.prev)) + return Ok(Empty(self.prev)); }; if *b == b'q' { self.i += 1; @@ -727,7 +729,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> } let t = self.get_term()?; let Some(b) = self.utf8.get(self.i) else { - return Ok(t) + return Ok(t); }; if *b == b'!' { self.i += 1; @@ -810,6 +812,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> /// a terminal expression; as a result, it is the only terminal expression /// that does not return an `Option`. #[cfg(feature = "rand")] + #[allow(clippy::host_endian_bytes)] #[inline] fn get_rand(&mut self) -> Result<Ratio<BigInt>, LangErr> { /// Generates a random 64-bit integer. @@ -884,7 +887,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> // This is the last kind of terminal expression that is attempted. // If there is no more data, then we have a missing terminal expression. let Some(b) = self.utf8.get(self.i..self.i.saturating_add(5)) else { - return Err(MissingTerm(self.i)) + return Err(MissingTerm(self.i)); }; if b == b"rand(" { self.i += 5; @@ -902,7 +905,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> } else { let add = self.get_adds()?; let Some(b2) = self.utf8.get(self.i) else { - return Err(LangErr::InvalidRand(self.i)) + return Err(LangErr::InvalidRand(self.i)); }; if *b2 == b',' { self.i += 1; @@ -910,7 +913,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> let add2 = self.get_adds()?; self.consume_ws(); let Some(b3) = self.utf8.get(self.i) else { - return Err(LangErr::InvalidRand(self.i)) + return Err(LangErr::InvalidRand(self.i)); }; if *b3 == b')' { self.i += 1; @@ -934,7 +937,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> #[inline] fn get_round(&mut self) -> Result<Option<Ratio<BigInt>>, LangErr> { let Some(b) = self.utf8.get(self.i..self.i.saturating_add(6)) else { - return Ok(None) + return Ok(None); }; if b == b"round(" { self.i += 6; @@ -942,14 +945,14 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> let val = self.get_adds()?; self.consume_ws(); let Some(b2) = self.utf8.get(self.i) else { - return Err(InvalidRound(self.i)) + return Err(InvalidRound(self.i)); }; let b3 = *b2; if b3 == b',' { self.i += 1; self.consume_ws(); let Some(b4) = self.utf8.get(self.i) else { - return Err(InvalidRound(self.i)) + return Err(InvalidRound(self.i)); }; let r = if b4.is_ascii_digit() { self.i += 1; @@ -984,7 +987,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> #[inline] fn get_abs(&mut self) -> Result<Option<Ratio<BigInt>>, LangErr> { let Some(b) = self.utf8.get(self.i) else { - return Ok(None) + return Ok(None); }; if *b == b'|' { self.i += 1; @@ -992,7 +995,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> let r = self.get_adds()?; self.consume_ws(); let Some(b2) = self.utf8.get(self.i) else { - return Err(InvalidAbs(self.i)) + return Err(InvalidAbs(self.i)); }; let b3 = *b2; if b3 == b'|' { @@ -1018,7 +1021,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> #[allow(clippy::as_conversions, clippy::cast_possible_truncation)] fn get_recall(&mut self) -> Result<Option<Ratio<BigInt>>, LangErr> { let Some(b) = self.utf8.get(self.i) else { - return Ok(None) + return Ok(None); }; if *b == b'@' { self.i += 1; @@ -1044,7 +1047,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> #[inline] fn get_par(&mut self) -> Result<Option<Ratio<BigInt>>, LangErr> { let Some(b) = self.utf8.get(self.i) else { - return Ok(None) + return Ok(None); }; if *b == b'(' { self.i += 1; @@ -1052,7 +1055,7 @@ impl<'input, 'cache, 'prev, 'scratch> Evaluator<'input, 'cache, 'prev, 'scratch> let r = self.get_adds()?; self.consume_ws(); let Some(b2) = self.utf8.get(self.i) else { - return Err(InvalidPar(self.i)) + return Err(InvalidPar(self.i)); }; let b3 = *b2; if b3 == b')' { diff --git a/src/main.rs b/src/main.rs @@ -106,7 +106,7 @@ //! //! ## Rand expression //! -//! `rand(expression, expression)` generates a random 64-integer inclusively between the passed expressions. +//! `rand(expression, expression)` generates a random 64-bit integer inclusively between the passed expressions. //! An error will be displayed if called incorrectly. `rand()` generates a random 64-bit integer. //! //! ## Numbers @@ -180,8 +180,10 @@ #![allow( clippy::blanket_clippy_restriction_lints, clippy::implicit_return, + clippy::min_ident_chars, clippy::missing_trait_methods, - clippy::question_mark_used + clippy::question_mark_used, + clippy::single_call_fn )] use calc_lib::lending_iterator::LendingIterator; use calc_lib::EvalIter;