Crates.io | cio |
lib.rs | cio |
version | |
source | src |
created_at | 2025-04-29 20:40:16.361493+00 |
updated_at | 2025-05-07 20:25:34.824948+00 |
description | CIO provides two powerful procedural macros (`println!` and `input!`) that enhance console I/O operations in Rust, bringing Python-like convenience to Rust's type-safe environment. |
homepage | https://github.com/gerarddubard/cio |
repository | https://github.com/gerarddubard/cio |
max_upload_size | |
id | 1654040 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
CIO provides two powerful procedural macros (println!
and input!
) that bring Python-like convenience to Rust's type-safe environment. These macros streamline console interaction with advanced formatting and validation capabilities.
Add this to your Cargo.toml
:
[dependencies]
cio = "0.4.0"
println!
macro{var}
instead of {}
with separate arguments)@(...)
syntax:a
, :c
, :j
, :m
, :d
)$(...)
syntax to unify print!
and println!
std::collections
types with intuitive formattinginput!
macrochar
inputs)use cio::{println, input};
// Type-safe input collection with validation
let name: String = input!("Your name: ");
let age: i32 = input!("Your age: ");
let height: f64 = input!("Your height (in meters): ");
let married: bool = input!("Are you married? (true/false): ");
let favorite_letter: char = input!("What is your favorite letter? ");
// Direct variable names in placeholders (Python f-string style)
println!("Hello, {name}, you are {age} years old!");
// Apply colors and styles with @(...) syntax
println!("@(green, bold)Success:@() Operation completed!");
println!("@(red, italic)Error:@() Something went wrong.");
println!("@(blue)Information:@() System is @(yellow)running@() normally.");
// Mix variables with styling
println!("@(bright_cyan, bold)User:@() {name} (@(bright_green){age}@() years old)");
// Direct expressions in format placeholders
println!("Age in months: {age * 12}");
println!("Height in cm: {height * 100.0:.0}");
println!("Name in uppercase: {name.to_uppercase()}");
// Conditional expressions
println!("Status: {if age >= 18 { "Adult" } else { "Minor" }}");
// Method calls
println!("First letter: {name.chars().next().unwrap_or('?')}");
// No separator - works like println!
println!("Regular line with newline");
// With separator - works like print! with explicit separator
for i in 1..10 {
println!("{i}$( - )"); // Prints "1 - 2 - 3 - ..." on one line
}
// Dynamic separators with variables
let separator = " | ";
println!("Item: {item}$(separator)");
use std::collections::{HashMap, BTreeMap, VecDeque};
// Arrays and vectors
let numbers = vec![1, 2, 3, 4, 5];
println!("Numbers (array format): {numbers:a}"); // [1, 2, 3, 4, 5]
// Matrices
let matrix = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
println!("Matrix (standard format):\n{matrix:a}"); // Indented array
println!("Matrix (matrix format):\n{matrix:m}"); // With matrix borders
println!("Matrix (determinant format):\n{matrix:d}"); // With determinant bars
// HashMap
let mut capitals = HashMap::new();
capitals.insert("France", "Paris");
capitals.insert("Japan", "Tokyo");
println!("Capitals (pretty):\n{capitals:j}"); // JSON-like pretty format
println!("Capitals (compact): {capitals:c}"); // Single-line compact format
// Other collections
let queue = VecDeque::from([1, 2, 3, 4]);
println!("Queue: {queue:a}"); // Pretty prints any collection
// Deeply nested data
let nested = vec![
HashMap::from([
("name", "Alice"),
("scores", &[95, 87, 92])
]),
HashMap::from([
("name", "Bob"),
("scores", &[78, 85, 90])
])
];
println!("Nested data (pretty):\n{nested:j}");
// 3D arrays
let cube = vec![
vec![vec![1, 2], vec![3, 4]],
vec![vec![5, 6], vec![7, 8]]
];
println!("3D array:\n{cube:a}"); // Properly indented 3D structure
// String inputs (can't be empty)
let username: String = input!("Username: ");
// Numeric inputs (validates correct type)
let score: u32 = input!("Score (0-100): "); // Rejects non-numbers or floats
// Boolean inputs (accepts various formats)
let proceed: bool = input!("Continue? (y/n): "); // Accepts "true"/"false", "yes"/"no", "y"/"n", "1"/"0"
// Character inputs (ensures single character)
let grade: char = input!("Grade (A-F): "); // Rejects multiple characters
// Styled input prompts
let name = input!("@(green, bold)Your name:@() ");
let age = input!("@(bright_cyan)Your age:@() ");
// Errors are automatically displayed in red with blinking
// Error: invalid digit found in string
black
, red
, green
, yellow
, blue
, magenta
, cyan
, white
bright_black
, bright_red
, bright_green
, bright_yellow
, bright_blue
, bright_magenta
, bright_cyan
, bright_white
, gray
(alias for bright_black
)bold
, italic
, underline
, dimmed
, blink
, reversed
, hidden
, strikethrough
:a
- Array format with proper indentation for nested structures:c
- Compact single-line format for any data structure:j
- JSON-like pretty format for complex structures:m
- Matrix format with proper borders for 2D arrays:d
- Determinant format with vertical barsCIO combines the best of both worlds:
{var}
)This project is licensed under the MIT License.
CIO: Making console interaction in Rust as enjoyable as Python, but with the safety of Rust.