| Crates.io | literator |
| lib.rs | literator |
| version | 0.2.0 |
| created_at | 2025-09-06 11:40:11.327667+00 |
| updated_at | 2025-09-07 10:18:00.192029+00 |
| description | Efficient conversion of iterators to human-readable strings |
| homepage | |
| repository | https://github.com/simonask/literator |
| max_upload_size | |
| id | 1826984 |
| size | 46,365 |
This crate provides the Literator trait, which provides utilities for
efficiently displaying the items of an iterator without temporary allocations.
Additionally, a few general formatting utilities are provided for convenience,
including a polyfill for the unstable std::fmt::from_fn(), simple
Unicode-compatible case conversion display adapters, and repetition.
Efficient, allocation-free string concatenation:
# use literator::Literator;
let favorite_things = ["raindrops", "roses", "whiskers", "kittens"];
// This does not allocate:
let joined = favorite_things.iter().capitalize_first().join(", ");
let message = joined.to_string();
assert_eq!(message, "Raindrops, roses, whiskers, kittens");
Some things require special display logic that cannot be represented as slices without allocation, like paths:
# use literator::Literator;
# use std::path::Path;
let paths = [Path::new("foo"), Path::new("bar")];
let list = paths.iter().map(|p| p.display()).join(", ").to_string();
assert_eq!(list, "foo, bar");
Friendlier error messages with ad-hoc formatting:
# use literator::Literator;
#[derive(Debug, thiserror::Error)]
enum Crisis<'a> {
#[error(
"I need {}",
.0.iter().oxford_join_and()
)]
Craving(&'a [&'a str])
}
assert_eq!(
Crisis::Craving(&["pizza", "macaroni and cheese", "crackers"]).to_string(),
"I need pizza, macaroni and cheese, and crackers"
);
Debug/Display implementations for various adapters
render directly to the output stream.join(). The standard library only has
std::slice::join(),
which heap allocates and only works for slices, not iterators.
Itertools::join()
only works for Display, not Debug, and only supports using a &str as the delimiter.oxford_join() for listing items with appropriate punctuation. The
oxford_join
crate, while
great, only works on slices and collections, heap allocates the result, and
only supports string conjunctions. Literator::oxford_join_custom() supports
using any displayable delimiter, including non-English conjunctions.println!("{:.02}", [1.0, 2.0].iter().join(", ")) prints "1.00, 2.00".#![no_std]#![forbid(unsafe_code)]