calc_rational

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

commit 17b6e9cc78e7580fe09062be73d862b06a2c7fc6
parent a22c03483af9d215ab92df81c0312b2d08fff2c9
Author: Zack Newman <zack@philomathiclife.com>
Date:   Wed, 13 Sep 2023 11:56:10 -0600

update priv_sep

Diffstat:
MCargo.toml | 4++--
MREADME.md | 3+--
Msrc/main.rs | 16+++++++++-------
3 files changed, 12 insertions(+), 11 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.2" +version = "0.6.0" [lib] name = "calc_lib" @@ -24,7 +24,7 @@ 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.4.1", default-features = false, features = ["openbsd"], optional = true } +priv_sep = { version = "0.5.0", 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 @@ -151,8 +151,7 @@ lead to an error message. Errors due to a language violation (e.g., dividing by `0`) manifest into an error message. `panic!`s and [`io::Error`](https://doc.rust-lang.org/std/io/struct.Error.html)s caused by writing to the global standard output stream lead to program abortion. On OpenBSD-stable when compiled with the `priv_sep` feature, -it will error if [`pledge(2)`](https://man.openbsd.org/amd64/pledge.2) errors with the promise of `"stdio"` -returning the corresponding [`c_int`](https://doc.rust-lang.org/core/ffi/type.c_int.html). +it will error if [`pledge(2)`](https://man.openbsd.org/amd64/pledge.2) errors with the promise of `"stdio"`. ## Exiting diff --git a/src/main.rs b/src/main.rs @@ -151,7 +151,7 @@ //! and [`io::Error`](https://doc.rust-lang.org/std/io/struct.Error.html)s caused by writing to the global //! standard output stream lead to program abortion. On OpenBSD-stable when compiled with the `priv_sep` feature, //! it will error if [`pledge(2)`](https://man.openbsd.org/amd64/pledge.2) errors with the promise of -//! `"stdio"` returning the corresponding [`c_int`](https://doc.rust-lang.org/core/ffi/type.c_int.html). +//! `"stdio"`. //! //! ## Exiting //! @@ -192,6 +192,7 @@ use core::ffi::c_int; use core::fmt::{self, Display, Formatter}; #[cfg(all(feature = "priv_sep", target_os = "openbsd"))] use priv_sep::{self, Promise}; +use std::error; use std::io::{self, Error, Write}; /// Error returned by [`main`]. #[allow(clippy::exhaustive_enums)] @@ -201,7 +202,7 @@ pub enum Err { Error(Error), #[cfg(all(feature = "priv_sep", target_os = "openbsd"))] // Error returned from [`pledge`]. - Pledge(c_int), + Pledge(Error), } impl Display for Err { #[allow(clippy::ref_patterns)] @@ -210,18 +211,19 @@ impl Display for Err { match *self { Self::Error(ref e) => e.fmt(f), #[cfg(all(feature = "priv_sep", target_os = "openbsd"))] - Self::Pledge(c) => write!(f, "pledge(2)ing 'stdio' failed with {c}"), + Self::Pledge(ref e) => write!(f, "pledge(2)ing 'stdio' failed with {e}"), } } } -impl std::error::Error for Err {} +impl error::Error for Err {} /// Entry point to the calc program. /// /// # Errors /// -/// Returns [`Error`] iff [`writeln`] returns one when writing -/// to the global standard output stream. Returns [`c_int`](https://doc.rust-lang.org/stable/core/ffi/type.c_int.html) iff -/// [`pledge`](https://docs.rs/priv_sep/latest/priv_sep/fn.pledge.html) does when compiled with the `priv_sep` feature which +/// Returns [`Error`] if[`writeln`] returns one when writing +/// to the global standard output stream. Returns [`Error`] if +/// [`pledge`](https://docs.rs/priv_sep/latest/priv_sep/fn.pledge.html) +/// does when compiled with the `priv_sep` feature which /// currently only works on OpenBSD-stable. fn main() -> Result<(), Err> { /// Calls `pledge(2)` with the "stdio" promise.