TestUtils
A utility library providing various helper functions, macros, and tools for Rust development.
Features
-
all All available features enabled
-
std Enables standard library support. When enabled, the crate cannot be used in
no_std
environments. -
ext_traits Additional trait extensions:
BoolExt
- Adds.ok_or_else()
method forbool
type- Re-exports
Pipe
andTap
traits fromtap
crate
-
tiny_container Compact string (<=N: Inline(Stack), >N: Overflow to Heap):
TString<const N: usize>
type alias forTinyString<[u8; N]>
Formattable
trait- Enables
format
support forTString
- Enables
IntoBoxedStr
trait- Adds
.into_boxed_str()
conversion
- Adds
-
os_cmd
- Configurable command builders:
- Preconfigured cargo command structs (e.g.,
CargoDoc
,CargoCmd
) - Cross-platform command execution utilities
- Preconfigured cargo command structs (e.g.,
RunnableCommand
trait- Provides
.run()
- Provides
- Configurable command builders:
Macros
dbg_ref!
Prints debug information using log::debug!
instead of direct stderr output. Displays both the type and value of the passed argument.
Comparison with std::dbg!
:
- Uses structured logging instead of direct stderr output
- Requires logger initialization (e.g.,
env_logger
) - Shows full type paths for better diagnostics
use dbg_ref;
// env_logger::builder().filter_level(log::LevelFilter::Debug).init();
let x = 42;
dbg_ref!; // Prints: [DEBUG] x: i32 = 42
let y = "hello";
dbg_ref!; // Prints: [DEBUG] y: &str = "hello"
let z = vec!;
dbg_ref!; // Prints: [DEBUG] z: alloc::vec::Vec<i32> = [1, 2, 3]
dbg!
Similar to dbg_ref!
, but outputs content using eprintln!
instead of log::debug!
.
use dbg;
let x = 42;
dbg!; // Prints: x: i32 = 42
let y = "hello";
dbg!; // Prints: y: &str = "hello"
generate_struct_arr!
Converts a struct into an array of field-value tuples. Particularly useful for testing and configuration scenarios.
use generate_struct_arr;
let b = BuildStd ;
let arr = generate_struct_arr!;
assert_eq!;
OS Command Configuration
Raw String Configuration
Build commands using commented configuration strings with automatic comment stripping:
use io;
use ;
Preset Command: CargoDoc
Preconfigured command builder with sensible defaults:
Default Configuration:
CargoDoc
Usage Example:
use io;
use ;
Configuration Methods:
use ;
Key Methods:
with_pkg()
: Set package namewith_custom_cfg()
: Specify custom cfg attributeswith_nightly()
: Toggle nightly toolchainwith_open()
: Control browser auto-openingwith_enable_private_items()
: Toggle private item inclusionwith_all_features()
: Control feature activation
Preset Command: CargoCmd
Configuration struct for cargo build
command generation.
Used to generate precise cargo command-line arguments.
Default
CargoCmd
let vec = default
.with_nightly // Enables nightly channel features
.with_pkg // Macro-based package detection
.with_target // enum Target
.with_build_std
.with_build_std_features
.into_vec; // Finalize configuration to argument list
// Verify generated command structure matches expectations
assert_eq!;
// Convert to command executor
let runner: Runner = vec.into;
// Uncomment to execute:
// runner.run();