| Crates.io | prism3-core |
| lib.rs | prism3-core |
| version | 0.2.0 |
| created_at | 2025-10-13 17:26:37.408446+00 |
| updated_at | 2025-10-29 06:56:19.807413+00 |
| description | Foundational utilities and language-level tools for Rust application development |
| homepage | https://github.com/3-prism/prism3-rust-core |
| repository | https://github.com/3-prism/prism3-rust-core |
| max_upload_size | |
| id | 1880851 |
| size | 248,218 |
A comprehensive Rust utility library providing language-level fundamental tools and data type support for the Prism3 ecosystem.
Prism3 Core is designed to provide essential language-level utilities that are commonly needed across Rust applications. It offers robust argument validation, comprehensive data type definitions, and core utility functions that follow Rust idioms and best practices.
DataType enum supporting all basic Rust types and common third-party typesDataTypeOf trait for compile-time type-to-data-type queriesAdd this to your Cargo.toml:
[dependencies]
prism3-core = "0.1.0"
use prism3_core::lang::{DataType, DataTypeOf};
// Get data type information
let data_type = DataType::Int32;
assert_eq!(data_type.as_str(), "int32");
// Compile-time type mapping
assert_eq!(i32::DATA_TYPE, DataType::Int32);
assert_eq!(String::DATA_TYPE, DataType::String);
// Serialization
let json = serde_json::to_string(&DataType::Float64).unwrap();
assert_eq!(json, "\"float64\"");
use prism3_core::lang::argument::{
NumericArgument, StringArgument, CollectionArgument, ArgumentResult
};
use regex::Regex;
fn process_user_input(
age: i32,
username: &str,
tags: &[String],
) -> ArgumentResult<()> {
// Numeric validation
let age = age.require_in_closed_range("age", 0, 150)?;
// String validation with chaining
let username_pattern = Regex::new(r"^[a-zA-Z][a-zA-Z0-9_]{2,19}$").unwrap();
let username = username
.require_non_blank("username")?
.require_match("username", &username_pattern)?;
// Collection validation
let tags = tags
.require_non_empty("tags")?
.require_length_at_most("tags", 10)?;
println!("Age: {}, Username: {}, Tag count: {}", age, username, tags.len());
Ok(())
}
use prism3_core::lang::argument::{
check_argument, check_state, check_bounds, ArgumentResult
};
fn process_data(value: i32, items: &[String]) -> ArgumentResult<()> {
// Basic argument checking
check_argument(value > 0, "value must be positive")?;
// State validation
check_state(!items.is_empty(), "items cannot be empty")?;
// Bounds checking
check_bounds(value, 1, 100, "value")?;
Ok(())
}
i8, i16, i32, i64, i128, u8, u16, u32, u64, u128f32, f64bool, char, StringNaiveDate, NaiveTime, NaiveDateTime, DateTime<Utc>BigInt, BigDecimalDataType - Universal data type enumerationDataTypeOf - Compile-time type mapping traitNumericArgument - Numeric validation methodsStringArgument - String validation methodsCollectionArgument - Collection validation methodsOptionArgument - Option validation methodscheck_argument - Basic argument validationcheck_state - State validationcheck_bounds - Bounds checkingAll validation functions return ArgumentResult<T>, which is an alias for Result<T, ArgumentError>. The ArgumentError type provides detailed error information including:
use prism3_core::lang::argument::{ArgumentError, ArgumentResult};
match validate_input(value) {
Ok(result) => println!("Validation passed: {:?}", result),
Err(ArgumentError::InvalidArgument { param, message }) => {
eprintln!("Invalid argument '{}': {}", param, message);
}
}
This project maintains comprehensive test coverage with detailed validation of all functionality.
Current test coverage statistics:
| Module | Region Coverage | Line Coverage | Function Coverage |
|---|---|---|---|
| collection.rs | 100.00% | 100.00% | 100.00% |
| condition.rs | 100.00% | 100.00% | 100.00% |
| error.rs | 100.00% | 100.00% | 100.00% |
| numeric.rs | 100.00% | 100.00% | 100.00% |
| option.rs | 76.19% | 84.09% | 100.00% |
| string.rs | 100.00% | 100.00% | 100.00% |
| data_type.rs | 100.00% | 100.00% | 100.00% |
| pair.rs | 100.00% | 100.00% | 100.00% |
| triple.rs | 100.00% | 100.00% | 100.00% |
| Total | 98.38% | 98.99% | 100.00% |
The option.rs module shows 76.19% region coverage despite having 100% executable code coverage. This is due to a known characteristic of LLVM's coverage instrumentation:
LLVM Region Coverage Includes Non-Executable Code:
where clause constraintsThese declarative elements are assigned region IDs by LLVM but are not executable code. The actual implementation code in option.rs has 100% coverage (verified by examining the detailed report - no ^ markers indicating uncovered code).
Example:
pub trait OptionArgument<T> { // β Counted as region
fn require_non_null( // β Counted as region
self, // β Counted as region
name: &str // β Counted as region
) -> ArgumentResult<T>; // β Counted as region
fn require_non_null_and<F>( // β Counted as region
self, name: &str,
predicate: F,
error_msg: &str
) -> ArgumentResult<T>
where // β Counted as region
F: FnOnce(&T) -> bool; // β Counted as region
}
Why This Happens:
option.rs has ~88 lines of trait definitions with complex generic constraintserror.rs have fewer declarative regionsWhat Matters:
# Run all tests
cargo test
# Run with coverage report
./coverage.sh
# Generate text format report
./coverage.sh text
# Generate detailed report for specific module
cargo llvm-cov test --text | grep -A 50 "option.rs"
The coverage statistics are generated using cargo-llvm-cov. When interpreting the results:
^ markers in uncovered regionsFor more details, see:
target/llvm-cov/html/Copyright (c) 2025 3-Prism 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.
Contributions are welcome! Please feel free to submit a Pull Request.
When contributing tests, note that achieving 100% region coverage is not always feasible for modules with extensive trait definitions. Focus on ensuring all executable code paths are tested.
Haixing Hu - 3-Prism Co. Ltd.
For more information about the Prism3 ecosystem, visit our GitHub homepage.