Veclite: A Vec<T> alternative

Veclite

Veclite implements std::fmt::Display, allowing for formatting and readable text.

Install

Add this to your Cargo.toml:

[dependencies]
veclite = "1.0.0"

How to use

Veclite is normally used using the Vel alias:

use veclite::Vel;

fn main() {
   let mut list = Vel::new;
   list.add(1);
   list.add(2);
   list.add(3);
   println!("List: {}", list)
}

You can also use the Veclite struct, which is more inconvenient:

use veclite::Veclite;

fn main() {
   let mut list = Veclite::new;
   list.add(1);
   list.add(2);
   list.add(3);
   println!("List: {}", list)
}

You can suggest improvements or contribute at https://github.com/Pjdur/Veclite/contribute

For the claim of a drop-in replacement it's lacking a whole bunch of methods and trait implementations.
Also Clone could have just be derived.
Also, why do you have a partial API, if you're exposing the inner Vec anyways?

This could be #![no_std] using alloc::vec::Vec instead.

The "missing" APIs could be transparently exposed by implementing Deref and DerefMut to the inner Vec.

2 Likes

Maybe the claim of drop-in replacement is false, and other mistakes, but it still does work and I use it. It exposes the inner Vec as it doesn't implemenet all of Vec's methods yet.

I will change it to use alloc::vec::Vec later, but the crate is actually alpha. It can be used, but not fully implemented.

Veclite now uses alloc, and uses Deref instead of manually implementing methods.
https://crates.io/crates/veclite/1.0.0

2 Likes

I still wonder, why you’re going through all the kerfuffle of exposing a partial Vec's API if your main and maybe only goal is to make a Vec displayable. Something like this would be more concise and universal:

Also, don’t delegate formatting to the elements by write!(f, “{item}”). It prevents the items to access the actual formatter’s settings, such as .alternate() et al. Use item.fmt(f) instead.

4 Likes

Veclite's primary goal was to make Vec displayable, but it's now mainly a way of knowing how Vec works.

This has been addressed in version 1.0.1.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.