#format #display #lightweight

no-std display_utils

Lightweight and no_std-compatible string formatting utilities

5 releases (3 breaking)

0.4.0 Mar 5, 2021
0.3.0 Jan 12, 2021
0.2.0 Jan 11, 2021
0.1.1 Jan 9, 2021
0.1.0 Jan 9, 2021

#289 in Debugging

Download history 81/week @ 2022-05-27 123/week @ 2022-06-03 10/week @ 2022-06-10 111/week @ 2022-06-17 27/week @ 2022-06-24 104/week @ 2022-07-01 38/week @ 2022-07-08 62/week @ 2022-07-15 142/week @ 2022-07-22 172/week @ 2022-07-29 139/week @ 2022-08-05 149/week @ 2022-08-12 114/week @ 2022-08-19 100/week @ 2022-08-26 98/week @ 2022-09-02 70/week @ 2022-09-09

382 downloads per month

MIT license

34KB
548 lines

This no_std compatible library provides several useful constructs to format data in a human-readable fashion with zero allocations.

Why hand-roll annoying and verbose formatting code everywhere...

for i, item in list.iter().enumerate() {
	if i == list.len() - 1 {
		println!("{}", item);
	} else {
		print!("{} - ", item);
	}
}

...when you could just use this?

println!("{}", display_utils::join(list, " - "));

This library makes ingenious use of Rust's formatting abstractions to provide super flexible and powerful formatting utilities, without any allocations.

For more information, please see the documentation: https://docs.rs/display_utils


lib.rs:

This library aims to provide useful constructs to vastly simplify data formatting tasks.

Being a no_std library, no allocations will be made, ever. Even with this restriction however, the provided functions are flexible and ergonomic.

This code snippet:

# let list = &[1, 2, 3];
for (i, item) in list.iter().enumerate() {
    if i == list.len() - 1 {
        println!("{}", item);
    } else {
        print!("{} - ", item);
    }
}

...simplifies to:

# let list = &[1, 2, 3];
println!("{}", display_utils::join(list, " - "));

Other functions work in a similar fashion. Browser through the crate functions for an overview of what you can do.

Extension traits ([DisplayExt], [IteratorExt]) which may be used to make method chains more readable.

No runtime deps