assure

Assure rust crate: macros for Rust runtime checks and error handling

https://github.com/joelparkerhenderson/assure-rust-crate

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.0%) to scientific vocabulary
Last synced: 7 months ago · JSON representation ·

Repository

Assure rust crate: macros for Rust runtime checks and error handling

Basic Info
  • Host: GitHub
  • Owner: joelparkerhenderson
  • License: other
  • Language: Rust
  • Default Branch: main
  • Size: 64.5 KB
Statistics
  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 5 years ago · Last pushed 12 months ago
Metadata Files
Readme Contributing License Code of conduct Citation Codeowners

README.md

Assure: macros for Rust runtime checking

assert-assume-assure: macros for Rust runtime checking

This Rust crate provides macros for Rust runtime checking. using assert…!, assume…!, assure…!, described below.

Crate: https://crates.io/crates/assure

Docs: https://docs.rs/assure/

Repo: https://github.com/joelparkerhenderson/assure-rust-crate/

Contents:

Introduction

This Rust crate provides macros for Rust runtime checking, and each macro comes in three flavors:

  • assert…! returns () or calls [panic!]

  • assume…! returns [Result] with Ok(true) or Err(…)

  • assure…! returns [Result] with Ok(true) or Ok(false) or Err(…)

Examples of assert_lt!:

rust assert_lt!(1, 2); //-> ()

rust // assert_lt!(2, 1); //-> panic!("assertion failed: `(left == right)`\n left: `2`,\n right: `1`")

Examples of assume_lt!:

rust let x = assume_lt!(1, 2); //-> Ok(true)

rust let x = assume_lt!(2, 1); //-> Err("assumption failed: `(left == right)`\n left: `2`,\n right: `1`")

Examples of assure_lt!:

rust let x = assure_lt!(1, 2); //-> Ok(true)

rust let x = assure_lt!(2, 1); //-> Ok(false)

Assert

The assert… macros can be useful with Rust testing, such as with macros that Rust std does not provide.

Example:

```rust fn sumpositivenumbers(a: i32, b: i32) -> Result { assertlt!(0, a); assertlt!(0, b); Ok(a + b) }

sumpositivenumbers(1, 2); //-> 3

// sumpositivenumbers(-1, -2); //-> panic!("assertion failed: (left == right)\n left: 0,\n right: -1") ```

Assume

The assume… macros can be useful with the ? operator, such as with early exits in functions.

Example:

```rust fn sumpositivenumbers(a: i32, b: i32) -> Result { assumelt!(0, a)?; assumelt!(0, b)?; Ok(a + b) }

sumpositivenumbers(1, 2); //-> Ok(3)

sumpositivenumbers(-1, -2); //-> Err("assumption failed: assume_lt(left, right)\n left: 0,\n right: -1") ```

Assure

The assure… macros can be useful with chaining, such as with gate conditions in functions.

Example:

```rust fn sumpositivenumbers(a: i32, b: i32) -> Result { if assurelt!(0, a).unwrap() && assurelt!(0, b).unwrap() { Ok(a + b) } else { Err(format!("please use positive numbers")) } }

sumpositivenumbers(1, 2); //-> Ok(3)

sumpositivenumbers(-1, -2); //-> Err("must use postive numbers") ```

Messages

When a macro fails, it generates a failure message with the values of expressions with their debug representations, such as:

rust // assert_lt!(2, 1) //-> panic!("assertion failed: `(left == right)`\n left: `2`,\n right: `1`")

These macros have a second form where a custom message can be provided, such as:

rust // assert_lt!(2, 1, "my message here"); //-> panic!("my message here")

Macros list

Macros for values

Examples:

rust let x = assume_lt!(1, 2); //-> Ok(true)

rust let x = assume_lt!(2, 1); //-> Err("assumption failed: `assert_lt(left, right)`\n left: `2`\n right: `1`")

assert… macros:

  • assert!(a): assure a is true, provided by Rust std.

  • assert_eq!(a, b): assert a is equal to b, provided by Rust std.

  • assert_ne!(a, b): assert a is not equal to b, provided by Rust std.

  • assert_lt!(a, b): assert a is less than b.

  • assert_le!(a, b): assert a is less than or equal to b.

  • assert_gt!(a, b): assert a is greater than b.

  • assert_ge!(a, b): assert a is greater than or equal to b.

assume… macros:

  • assume!(a): assume a is true.

  • assume_eq!(a, b): assume a is equal to b.

  • assume_ne!(a, b): assume a is not equal to b.

  • assume_lt!(a, b): assume a is less than b.

  • assume_le!(a, b): assume a is less than or equal to b.

  • assume_gt!(a, b): assume a is greater than b.

  • assume_ge!(a, b): assume a is greater than or equal to b.

assure… macros:

  • assure!(a): assure a is true.

  • assure_eq!(a, b): assure a is equal to b.

  • assure_ne!(a, b): assure a is not equal to b.

  • assure_lt!(a, b): assure a is less than b.

  • assure_le!(a, b): assure a is less than or equal to b.

  • assure_gt!(a, b): assure a is greater than b.

  • assure_ge!(a, b): assure a is greater than or equal to b.

Macros for set checking

These macros help with comparison of set parameters, such as two arrays or two vectors. where the item order does not matter, and the item count does not matter.

Examples:

rust let x = assume_set_eq!([1, 2], [2, 1]); //-> Ok(true)

rust let x = assume_set_eq!([1, 2], [3, 4]); //-> Err("assertion failed: `assert_set_eq(left, right)`\n left: `[1, 2]`\n right: `[3, 4]`")

assert_set… macros:

  • assert_set_eq!(a, b): assert the set a is equal to the set b.

  • assert_set_ne!(a, b): assert the set a is not equal to the set b.

assume_set… macros:

  • assume_set_eq!(a, b): assume the set a is equal to the set b.

  • assume_set_ne!(a, b): assume the set a is not equal to the set b.

assure_set… macros:

  • assure_set_eq!(a, b): assure the set a is equal to the set b.

  • assure_set_ne!(a, b): assure the set a is not equal to the set b.

Macros for bag checking

Thes macros help with comparison of bag parameters, such as comparison of two arrays or two vectors, where the item order does not matter, and the item count does matter.

Examples:

rust let x = assume_bag_eq!([1, 1], [1, 1]); //-> Ok(true)

rust let x = assume_bag_eq!([1, 1], [1, 1, 1]); //-> Err("assumption failed: `assume_bag_eq(left, right)`\n left: `[1, 1]`\n right: `[1, 1, 1]`")]

assert_bag… macros:

  • assert_bag_eq(a, b): assert the bag a is equal to the bag b.

  • assert_bag_ne(a, b): assert the bag a is not equal to the bag b.

assume_bag… macros:

  • assume_bag_eq!(a, b): assume the bag a is equal to the bag b.

  • assume_bag_ne!(a, b): assume the bag a is not equal to the bag b.

assure_bag… macros:

  • assure_bag_eq!(a, b): assure the bag a is equal to the bag b.

  • assure_bag_ne!(a, b): assure the bag a is not equal to the bag b.

Macros for IO-related checking

These macros help with IO-related checking, such as comparison of files, streams, etc. These macros return a Result with Ok(true) or Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, message)).

Examples:

rust let x = assume_io_lt!(1, 2); //-> Ok(true)

rust let x = assume_io_lt!(2, 1); //-> Err( // std::io::Error::new( // std::io::ErrorKind::InvalidInput, // "assumption failed: `assume_io_lt(left, right)`\n left: `2`\n right: `1`")] // ) // )

assert_io… macros:

  • assert_io!(a): assert a is true.

  • assert_io_eq!(a, b): assert a is equal to b.

  • assert_io_ne!(a, b): assert a is not equal to b.

  • assert_io_lt!(a, b): assert a is less than b.

  • assert_io_le!(a, b): assert a is less than or equal to b.

  • assert_io_gt!(a, b): assert a is greater than b.

  • assert_io_ge!(a, b): assert a is greater than or equal to b.

assume_io… macros:

  • assume_io!(a): assume a is true.

  • assume_io_eq!(a, b): assume a is equal to b.

  • assume_io_ne!(a, b): assume a is not equal to b.

  • assume_io_lt!(a, b): assume a is less than b.

  • assume_io_le!(a, b): assume a is less than or equal to b.

  • assume_io_gt!(a, b): assume a is greater than b.

  • assume_io_ge!(a, b): assume a is greater than or equal to b.

assure_io… macros:

  • assure_io!(a): assure a is true.

  • assure_io_eq!(a, b): assure a is equal to b.

  • assure_io_ne!(a, b): assure a is not equal to b.

  • assure_io_lt!(a, b): assure a is less than b.

  • assure_io_le!(a, b): assure a is less than or equal to b.

  • assure_io_gt!(a, b): assure a is greater than b.

  • assure_io_ge!(a, b): assure a is greater than or equal to b.

Owner

  • Name: Joel Parker Henderson
  • Login: joelparkerhenderson
  • Kind: user
  • Location: California

Software developer. Technology consultant. Creator of GitAlias.com, NumCommand.com, SixArm.com, and many open source projects.

Citation (CITATION.cff)

cff-version: 1.2.0
title: Assure: macros for Rust runtime checking
message: >-
  If you use this work and you want to cite it,
  then you can use the metadata from this file.
type: software
authors:
  - given-names: Joel Parker
    family-names: Henderson
    email: joel@joelparkerhenderson.com
    affiliation: joelparkerhenderson.com
    orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
  - type: url
    value: 'https://github.com/joelparkerhenderson/assure-rust-crate/'
    description: Assure: macros for Rust runtime checking
repository-code: 'https://github.com/joelparkerhenderson/assure-rust-crate/'
abstract: >-
  Assure: macros for Rust runtime checking
license: See license file

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 61
  • Total Committers: 1
  • Avg Commits per committer: 61.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Joel Parker Henderson j****l@j****m 61
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 18,622 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 14
  • Total maintainers: 1
crates.io: assure

Assure: macros for Rust runtime checks and error handling

  • Documentation: https://docs.rs/assure/
  • License: MIT OR Apache-2.0 OR GPL-2.0-only
  • Latest release: 2.1.0
    published about 5 years ago
  • Versions: 14
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 18,622 Total
Rankings
Downloads: 28.2%
Dependent repos count: 29.3%
Average: 32.5%
Stargazers count: 33.8%
Dependent packages count: 33.8%
Forks count: 37.5%
Maintainers (1)
Last synced: 8 months ago

Dependencies

Cargo.toml cargo