| Crates.io | pyprint |
| lib.rs | pyprint |
| version | 1.0.1 |
| created_at | 2025-04-18 21:59:11.694952+00 |
| updated_at | 2025-04-25 04:41:57.786883+00 |
| description | Library to enable python-style printing in rust |
| homepage | |
| repository | https://github.com/su-z/pyprint.git |
| max_upload_size | |
| id | 1639932 |
| size | 15,129 |
Getting tired of writing printing statements with format strings in Rust? This is a library to enable Python-style printing in Rust. It is implemented using Rust macros. Anything with the Display trait implemented can be printed.
DebugInstall with:
cargo add pyprint
Or add to your Cargo.toml:
[dependencies]
pyprint = "1.0.1"
Simply write like Python in Rust:
use pyprint::pprn;
// Basic printing
let a = 5;
pprn!("Progress:", a, sep=" ", end="\r"); // Prints: Progress: 5 (with carriage return)
// Multiple values
pprn!("Hello", "World", 42); // Prints: Hello World 42
// Custom separator
pprn!("a", "b", "c", sep=", "); // Prints: a, b, c
// Debug printing for complex types
use pyprint::dprn;
let data = vec![1, 2, 3];
dprn!(data); // Prints: [1, 2, 3]
use pyprint::eprn;
use pyprint::deprn;
// Regular error printing
eprn!("Error:", "File not found"); // Prints to stderr
// Debug error printing
deprn!(std::io::Error::last_os_error()); // Prints debug representation to stderr
use pyprint::pprint;
use std::fs::File;
// Print to a file (returns Result)
let file = File::create("output.txt").unwrap();
pprint!(file=file, "This goes to a file");
| Macro | Description |
|---|---|
pprint! |
Basic print, returns Result |
pprn! |
Basic print, unwraps Result |
dprint! |
Debug print, returns Result |
dprn! |
Debug print, unwraps Result |
eprint! |
Error print to stderr, returns Result |
eprn! |
Error print to stderr, unwraps Result |
deprint! |
Debug error print to stderr, returns Result |
deprn! |
Debug error print to stderr, unwraps Result |
All macros support these options:
sep=VALUE: Set separator between items (default: space)end=VALUE: Set ending string (default: newline)file=VALUE: Set output destination (default: stdout or stderr)flush=BOOL: Control immediate flushing (default: false). Note that when printing to the terminal, upon entering a new line, often flush will happen anyway.This project is licensed under the MIT License - see the LICENSE file for details.