veclite
A lightweight, ergonomic wrapper around Rust’s Vec<T> that implements Display for pretty printing and provides extra list-like utility methods.
Features
- Display Implementation: Print vector contents with
{}formatting — clean, space-separated output instead of debug-style brackets. - Utility Methods:
prepend,remove,get, and more — for convenient, list-like manipulation. - Short Alias: Use the ergonomic alias
Velfor idiomatic code. - Macro Support: Construct lists with the
vel![]macro, just likevec![]. - Familiar Semantics: Works like a
Vec<T>, but with extra display and usability power. - Trait Derivations: Implements
Debug,PartialEq,Clone, andDefault.
Quick Start
Add to your Cargo.toml
[]
= "1.0.1"
Import and use
use ;
let mut v = vel!;
v.prepend;
println!; // Output: greetings hello world
API Overview
Constructors and Methods
| Method | Description |
|---|---|
Vel::new() |
Create an empty list |
Vel::from(Vec) |
Convert from a standard Vec<T> |
prepend(value) |
Insert a value at the beginning |
push(value) |
Append a value to the end (via Vec) |
remove(index) |
Remove and return value at index |
get(index) |
Get reference to value at index |
iter() |
Iterate over values |
len() |
Number of elements |
is_empty() |
Check if empty |
| ... Other Vec methods are available directly |
Display
Implements [std::fmt::Display] for space-separated output:
let v = vel!;
println!; // Output: 1 2 3
Example Usage
use Vel;
More Examples
Integers
let v = vel!;
println!; // Output: 1 2 3
Strings
let names = vel!;
println!; // Output: Alice Bob
Iteration
let v = vel!;
for n in &v
// Output: 1-2-3-4-5-
FAQ
Q: Does veclite re-export all Vec methods?
A: Most methods are accessible via Deref, so you can use push, iter, sort, etc. directly. For advanced features, use .0 to access the inner Vec.
Q: Can I use veclite with non-displayable types?
A: Yes, but Display formatting requires T: Display. Other methods work for any T.
Q: Why not implement Display for Vec<T> directly?
A: The Rust standard library avoids this to prevent accidental large or slow prints. veclite lets you opt in explicitly.
Contributing
Bug reports, feature requests, and pull requests are welcome!
Open an issue or PR on GitHub.
License
Licensed under either of:
- MIT
- Apache-2.0
See Also