Crates.io | colprint |
lib.rs | colprint |
version | |
source | src |
created_at | 2025-05-07 23:24:47.319687+00 |
updated_at | 2025-05-07 23:24:47.319687+00 |
description | A lightweight macro for neatly printing data in aligned columns with automatic width calculation and customisable separators. |
homepage | |
repository | https://github.com/FreddyWordingham/colprint |
max_upload_size | |
id | 1664659 |
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 |
A lightweight Rust library for neatly printing data in aligned columns with automatic width calculation and customizable separators.
Display
, Debug
, and PrettyDebug
formattersAdd this to your Cargo.toml
:
[dependencies]
colprint = "0.0.0"
use colprint::colprint;
fn main() {
let name = "Alice";
let age = 30;
// Basic display formatting
colprint!("{} | {}", name, age);
}
Alice | 30
The colprint!
macro is most useful when printing complex (multi-line) data structures:
use colprint::colprint;
#[derive(Debug)]
struct Person {
name: String,
age: u32,
country: String,
job: String,
hobby: String,
}
impl std::fmt::Display for Person {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Name: {}\nAge: {}\nCountry: {}\nJob {}\nHobby {}",
self.name, self.age, self.country, self.job, self.hobby
)
}
}
fn main() {
let bob = Person {
name: "Bob".to_string(),
age: 25,
country: "Canada".to_string(),
job: "Data Scientist".to_string(),
hobby: "Photography".to_string(),
};
let jessica = Person {
name: "Jessica".to_string(),
age: 28,
country: "USA".to_string(),
job: "Software Engineer".to_string(),
hobby: "Hiking".to_string(),
};
colprint!("{}\t{}", bob, jessica);
}
Name: Bob Name: Jessica
Age: 25 Age: 28
Country: Canada Country: USA
Job Data Scientist Job Software Engineer
Hobby Photography Hobby Hiking
Also supports debug formatting:
colprint!("{:#?}\t{:#?}", bob, jessica);
Person { Person {
name: "Bob", name: "Jessica",
age: 25, age: 28,
country: "Canada", country: "USA",
job: "Data Scientist", job: "Software Engineer",
hobby: "Photography", hobby: "Hiking",
} }
This project is licensed under the MIT License - see the LICENSE file for details.