Crates.io | swift-check |
lib.rs | swift-check |
version | 0.2.1 |
source | src |
created_at | 2024-04-22 04:13:59.855095 |
updated_at | 2024-07-24 17:20:57.851475 |
description | High-performance, robust, and expressive searching and validation (uses SIMD on x86_64, aarch64, and WASM) |
homepage | |
repository | https://github.com/IronVelo/swift-check |
max_upload_size | |
id | 1215862 |
size | 119,237 |
Swift Check is a robust high-performance library designed for searching and validating data via expressive conditions.
experimental
feature)Add Swift Check to your project by including it in your Cargo.toml:
[dependencies]
swift-check = "0.2.1"
Using this library is fairly straight forward, swift-check
exposes various conditions that can be composed with each
other to create complex and performant searches / validators.
Search for the first comma:
use swift_check::{search, eq};
fn main() {
let input = b"hello, world!";
let Some(first_comma) = search(input, eq(b',')) else {
unreachable!("There's a comma!")
};
assert_eq!(input[first_comma], b',');
}
Ensure every byte is a letter, number, or space:
use swift_check::{for_all_ensure, any, range, eq};
fn main() {
let input = b"Hello World 12345";
let res = for_all_ensure(input, any!(
range!(b'A'..=b'Z'), range!(b'a'..=b'z'),
range!(b'0'..=b'9'), eq(b' ')
));
assert!(res);
}
This crate's minimum supported rustc
version is 1.61.0
To compensate for the great deal of unsafe
this crate leverages rigorous testing methodologies:
arch/simd_scan.rs
) each function is annotated with pre- and
post-conditions which are statically verified.We warmly welcome contributions from the community! If you're interested in helping Swift Check grow and improve, here are the areas we're currently focusing on:
This library is in its early stages, having started as an exploratory project. We've been delighted to find that our "what if" scenario is not only possible but promising. Currently, our primary focus is on ensuring that the library functions correctly, while recognizing that there are several opportunities for optimization in the scanning process.
In our performance evaluations, we discovered that the use of higher-order functions do not adversely affect performance. We experimented with various implementations, including one where variadic macros created structs to maintain SIMD registers throughout the search process. This approach performed comparably to our higher-order implementation. The main advantage of the struct-based approach is its ability to selectively utilize SIMD; for example, it enables us to perform simple searches over smaller inputs instead of relying on partial SIMD loads. However, the trade-off is complexity: adopting this method could require shifting to procedural macros or requiring users to provide identifiers for each condition in our declarative macros.