Qubit Argument
Argument and state validation utilities for Rust.
Overview
Qubit Argument provides extension traits and checking functions for validating
function arguments, configuration values, indexes, ranges, and runtime state.
It uses Rust's trait extension pattern for readable validation chains while
returning a small structured ArgumentError.
Design Goals
- Readable validation: express checks close to the value being validated.
- Small error surface: use
ArgumentErrorandArgumentResultfor all validation failures. - Method chaining: return validated values or references so checks compose naturally.
- No panic by default: report invalid arguments through
Result. - Focused scope: provide validation utilities only, without pulling in broader common utilities.
Features
Numeric Validation
- Zero and non-zero checks.
- Positive, negative, non-positive, and non-negative checks.
- Closed, open, left-open, and right-open range validation.
- Less-than, less-or-equal, greater-than, and greater-or-equal checks.
- Equality and inequality validation across two named arguments.
String Validation
- Non-blank checks.
- Exact length, minimum length, maximum length, and range length checks.
- Regular expression match and non-match checks.
- Implementations for both
strandString.
Collection and Option Validation
- Non-empty collection checks.
- Collection length constraints.
- Optional value presence checks.
- Conditional validation for present optional values.
- Element non-null checks for
&[Option<T>].
State and Bounds Checking
- Boolean argument and state assertions.
- Slice-style bounds checks.
- Element index, position index, and position index range validation.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Numeric and String Validation
use ;
Collection Validation
use ;
State and Bounds Checking
use ;
API Reference
Traits
NumericArgument- numeric validation methods.StringArgument- string validation methods.CollectionArgument- collection validation methods.OptionArgument- optional value validation methods.
Error Types
ArgumentError- validation error with a human-readable message.ArgumentResult- result alias returned by validation APIs.
Functions
check_argument,check_argument_with_message,check_argument_fmtcheck_state,check_state_with_messagecheck_bounds,check_element_index,check_position_index,check_position_indexesrequire_equal,require_not_equal,require_element_non_null,require_null_or
Testing & Code Coverage
This project maintains comprehensive test coverage for success paths, failure paths, boundary conditions, and representative type instantiations.
Running Tests
# Run all tests
# Run with coverage report
# Generate text format report
# Run CI checks (format, clippy, test, coverage, audit)
Coverage Metrics
See COVERAGE.md for detailed coverage statistics.
Dependencies
Runtime dependencies are intentionally small:
regexpowers regular expression validation for strings.
License
Copyright (c) 2025 - 2026. Haixing Hu, Qubit Co. Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
See LICENSE for the full license text.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Guidelines
- Follow the Rust API guidelines.
- Maintain comprehensive test coverage.
- Document all public APIs with examples when they clarify usage.
- Run
./ci-check.shbefore submitting PRs.
Author
Haixing Hu - Qubit Co. Ltd.
Related Projects
More Rust libraries from Qubit are published under the qubit-ltd organization on GitHub.
Repository: https://github.com/qubit-ltd/rs-argument