assure
Assure rust crate: macros for Rust runtime checks and error handling
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
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
Metadata Files
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] withOk(true)orErr(…)assure…!returns [Result] withOk(true)orOk(false)orErr(…)
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
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
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
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): assureais true, provided by Ruststd.assert_eq!(a, b): assertais equal tob, provided by Ruststd.assert_ne!(a, b): assertais not equal tob, provided by Ruststd.assert_lt!(a, b): assertais less thanb.assert_le!(a, b): assertais less than or equal tob.assert_gt!(a, b): assertais greater thanb.assert_ge!(a, b): assertais greater than or equal tob.
assume… macros:
assume!(a): assumeais true.assume_eq!(a, b): assumeais equal tob.assume_ne!(a, b): assumeais not equal tob.assume_lt!(a, b): assumeais less thanb.assume_le!(a, b): assumeais less than or equal tob.assume_gt!(a, b): assumeais greater thanb.assume_ge!(a, b): assumeais greater than or equal tob.
assure… macros:
assure!(a): assureais true.assure_eq!(a, b): assureais equal tob.assure_ne!(a, b): assureais not equal tob.assure_lt!(a, b): assureais less thanb.assure_le!(a, b): assureais less than or equal tob.assure_gt!(a, b): assureais greater thanb.assure_ge!(a, b): assureais greater than or equal tob.
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 setais equal to the setb.assert_set_ne!(a, b): assert the setais not equal to the setb.
assume_set… macros:
assume_set_eq!(a, b): assume the setais equal to the setb.assume_set_ne!(a, b): assume the setais not equal to the setb.
assure_set… macros:
assure_set_eq!(a, b): assure the setais equal to the setb.assure_set_ne!(a, b): assure the setais not equal to the setb.
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 bagais equal to the bagb.assert_bag_ne(a, b): assert the bagais not equal to the bagb.
assume_bag… macros:
assume_bag_eq!(a, b): assume the bagais equal to the bagb.assume_bag_ne!(a, b): assume the bagais not equal to the bagb.
assure_bag… macros:
assure_bag_eq!(a, b): assure the bagais equal to the bagb.assure_bag_ne!(a, b): assure the bagais not equal to the bagb.
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): assertais true.assert_io_eq!(a, b): assertais equal tob.assert_io_ne!(a, b): assertais not equal tob.assert_io_lt!(a, b): assertais less thanb.assert_io_le!(a, b): assertais less than or equal tob.assert_io_gt!(a, b): assertais greater thanb.assert_io_ge!(a, b): assertais greater than or equal tob.
assume_io… macros:
assume_io!(a): assumeais true.assume_io_eq!(a, b): assumeais equal tob.assume_io_ne!(a, b): assumeais not equal tob.assume_io_lt!(a, b): assumeais less thanb.assume_io_le!(a, b): assumeais less than or equal tob.assume_io_gt!(a, b): assumeais greater thanb.assume_io_ge!(a, b): assumeais greater than or equal tob.
assure_io… macros:
assure_io!(a): assureais true.assure_io_eq!(a, b): assureais equal tob.assure_io_ne!(a, b): assureais not equal tob.assure_io_lt!(a, b): assureais less thanb.assure_io_le!(a, b): assureais less than or equal tob.assure_io_gt!(a, b): assureais greater thanb.assure_io_ge!(a, b): assureais greater than or equal tob.
Owner
- Name: Joel Parker Henderson
- Login: joelparkerhenderson
- Kind: user
- Location: California
- Website: http://www.joelparkerhenderson.com
- Repositories: 319
- Profile: https://github.com/joelparkerhenderson
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
Top Committers
| Name | 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