rs-utils

Rust CI Coverage Crates.io Rust License 中文文档

General-purpose, dependency-light utilities for Rust projects. This crate gives Qubit applications one shared implementation for standard-range algebra, fallible allocation, runtime-only values, and audited low-level slice access.

Intended Users

Rust developers who need small, reusable building blocks across Qubit projects without adopting a broad framework or duplicating boundary-sensitive code.

Installation

Add the published crate to your Cargo.toml:

[dependencies]
qubit-utils = "0.3"

Quick Start

Suppose a service accepts a requested numeric window but may process only values inside a configured policy window. The range helpers accept standard Rust range syntax and return owned standard-library bounds:

use std::ops::Bound::Excluded;
use std::ops::Bound::Included;

use qubit_utils::range::encloses;
use qubit_utils::range::intersection;

let policy = 1..10;
let requested = 5..=20;
let accepted = intersection(&policy, &requested);

assert_eq!(accepted, Some((Included(5), Excluded(10))));
assert!(encloses(&policy, &accepted.expect("the windows overlap")));

The result is a (Bound<T>, Bound<T>), which already implements RangeBounds<T> and can be passed to ordered standard-library collection APIs.

Why This Project Exists

Boundary-heavy helpers are easy to get almost right and costly to maintain in multiple crates. qubit-utils centralizes the small contracts that recur across Qubit software while preserving standard Rust representations and keeping the default dependency surface small.

Current Status

The current version provides several reusable utility APIs:

Capabilities

The range module works with std::ops::RangeBounds, including normal Rust range syntax and arbitrary (Bound<T>, Bound<T>) pairs. It adds stable free functions for the range relationships and operations that are not yet available as a complete stable standard-library API.

The remaining modules provide reusable memory, numeric, slice, and runtime-state helpers used by adjacent Qubit Rust crates. Existing crate-root re-exports remain available for their commonly used types and functions.

Limitations

Range algebra other than is_empty requires a total order (Ord). Use an explicit ordered wrapper when working with floating-point values whose NaN semantics need a policy. Range emptiness follows endpoint-order semantics and does not canonicalize a discrete domain, so an open integer range such as (1, 2) is not treated as empty merely because no integer lies between its endpoints.

The crate intentionally does not define a custom interval type, dynamic comparators, discrete-domain stepping, or domain-specific date and money range types. Additional helpers are added only when they are broadly reusable.

Testing

# Run tests with the default feature set
cargo test

# Run tests with all declared features
cargo test --all-features

# Project CI checks
./.infra/bin/ci-check.sh

# Check code coverage
./.infra/bin/coverage.sh

License

Copyright (c) 2025 - 2026. Haixing Hu. All rights reserved.

Licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Contributing

Contributions are welcome. Please follow the Rust API guidelines, keep public API documentation and tests current, and run ./.infra/bin/align-ci.sh to format code and ./.infra/bin/ci-check.sh to satisfy CI requirements before submitting a pull request.

Author

Haixing Hu - Qubit Co. Ltd.

Repository: https://github.com/qubit-ltd/rs-utils