CIO - Console I/O for Rust (v0.2.0)
CIO provides two powerful procedural macros (input! and printf!) that bring Python-like convenience to Rust's type-safe environment.
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
1. Basic Input and Variable Display
The input! macro eliminates boilerplate code for user input handling with built-in validation:
// Type-safe input collection for various types
let first_name: String = input!;
let last_name: String = input!;
let age: i32 = input!;
let height: f64 = input!;
let married: bool = input!;
let favorite_letter: char = input!;
// Simple variable display
let status = if married else ;
printf!;
2. Expressions in Placeholders
The printf! macro supports complex expressions directly within placeholders:
// Direct mathematical operations
printf!;
printf!;
// Method calls within placeholders
printf!;
// Conditional expressions and ternary-like operations
let letter_category = if favorite_letter.is_alphabetic else if favorite_letter.is_numeric else ;
printf!;
// Complex expressions combining multiple operations
let letter_position = favorite_letter.to_uppercase.to_string.chars.next.unwrap as u8 - 64;
printf!;
3. Number Formatting
Full support for Rust's standard formatting options with extended capabilities:
let pi = PI;
printf!;
printf!;
printf!;
printf!;
printf!;
printf!;
printf!;
printf!;
printf!;
printf!;
printf!;
4. Multidimensional Arrays and Matrices
The printf! macro excels at displaying complex data structures:
// 1D array - Vector
let vec_1d = vec!;
// 2D array - Square matrices
let matrix_2x2 = vec!;
let matrix_3x3 = vec!;
// 3D, 5D, and even 7D arrays
let vec_3d = vec!;
// (5D and 7D arrays omitted for brevity)
// Format comparison for arrays
printf!;
printf!;
printf!;
// Matrix display with different formatters
printf!;
// Output:
// ⎛ 4 3 ⎞
// ⎝ 2 1 ⎠
printf!;
// Output:
// │ 1 2 3 │
// │ 4 5 6 │
// │ 7 8 9 │
// Special matrix shapes
printf!;
printf!;
5. Associative Containers and Complex Structures
The printf! macro handles any collection from std::collections:
// HashMap
let mut hash_map = new;
hash_map.insert;
hash_map.insert;
hash_map.insert;
// BTreeMap, HashSet, BTreeSet
let mut btree_map = new;
btree_map.insert;
btree_map.insert;
btree_map.insert;
// Display options
printf!;
printf!;
printf!;
// Complex nested structures
let mut cities_data = new;
// (Nested structure setup code omitted for brevity)
printf!;
// Deep access to nested elements
let paris_population = cities_data
.get
.and_then
.and_then
.unwrap_or;
printf!;
6. Advanced Turbofish and Complex Type Manipulation
The printf! macro seamlessly handles complex Rust idioms:
// Turbofish with method chaining
let numbers = vec!;
// Example: Filtering, transformation and collection
let even_squares: = numbers.iter
.filter // Keep only even numbers
.map // Square each number
.collect; // Collect into Vec<i32>
printf!;
printf!;
// Example: Complex operations with custom types
// Collection of custom structures
let people = vec!;
// Advanced grouping
let mut grouped_by_age: = new;
for p in &people
printf!;
7. Format Recommendation Summary
printf!;
printf!;
printf!;
printf!;
printf!;
printf!;
Key Features
- Versatile Formatting: Handle any collection from
std::collections(HashMap, BTreeMap, HashSet, BTreeSet, VecDeque, LinkedList, BinaryHeap) - Matrix Visualization: Beautiful display of matrices with proper notation
- Nested Structures: Intuitive formatting for deeply nested data structures
- Expression Support: Use complex expressions directly within format strings
- Type Safety: Maintain Rust's safety guarantees with convenient Python-like syntax
- Turbofish Compatible: Works seamlessly with Rust's advanced type system features
License
This project is licensed under the MIT License.