#![doc = include_str!("../README.md")]
#![no_std]
#![forbid(unsafe_code, missing_docs)]
use core::fmt::{Display, Formatter};
#[cfg(test)]
extern crate alloc;
pub mod block;
pub mod decorate;
pub mod fmt;
pub mod join;
mod literate;
mod literator;
use block::*;
use decorate::*;
use fmt::*;
use join::*;
pub use literate::*;
pub use literator::*;
macro_rules! impl_fmt_trait {
($trait:ident) => {
impl<D, I> core::fmt::$trait for Join<I, D>
where
I: Iterator<Item: core::fmt::$trait>,
D: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.do_fmt(f, core::fmt::$trait::fmt)
}
}
impl<I, D, L> core::fmt::$trait for ConjunctiveJoin<I, D, L>
where
I: Iterator<Item: core::fmt::$trait>,
D: Display,
L: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.do_fmt(f, core::fmt::$trait::fmt)
}
}
impl<I, D1, D2, D3> core::fmt::$trait for OxfordJoin<I, D1, D2, D3>
where
I: Iterator<Item: core::fmt::$trait>,
D1: Display,
D2: Display,
D3: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.do_fmt(f, core::fmt::$trait::fmt)
}
}
impl<I, Open, Delim, Close> core::fmt::$trait for InlineBlock<I, Open, Delim, Close>
where
I: Iterator<Item: core::fmt::$trait>,
Open: Display,
Delim: Display,
Close: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.do_fmt(f, core::fmt::$trait::fmt)
}
}
impl<I, Open, Close, Indentation, Newline> core::fmt::$trait
for IndentedBlock<I, Open, Close, Indentation, Newline>
where
I: Iterator<Item: core::fmt::$trait>,
Open: Display,
Close: Display,
Indentation: Display,
Newline: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.do_fmt(f, core::fmt::$trait::fmt)
}
}
impl<T: core::fmt::$trait, P: Display> core::fmt::$trait for Prefix<T, P> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.prefix)?;
self.item.fmt(f)
}
}
impl<T: core::fmt::$trait, S: Display> core::fmt::$trait for Suffix<T, S> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.item.fmt(f)?;
write!(f, "{}", self.suffix)
}
}
impl<T: core::fmt::$trait, Prefix: Display, Suffix: Display> core::fmt::$trait
for Surround<T, Prefix, Suffix>
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.prefix)?;
self.item.fmt(f)?;
write!(f, "{}", self.suffix)
}
}
impl<T, F> core::fmt::$trait for PrefixWith<T, F>
where
T: core::fmt::$trait,
F: Fn(&T, &mut Formatter) -> core::fmt::Result,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
(self.with)(&self.item, f)?;
self.item.fmt(f)
}
}
impl<T, F> core::fmt::$trait for SuffixWith<T, F>
where
T: core::fmt::$trait,
F: Fn(&T, &mut Formatter) -> core::fmt::Result,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
self.item.fmt(f)?;
(self.with)(&self.item, f)
}
}
};
}
impl_fmt_trait!(Display);
impl_fmt_trait!(Debug);
impl_fmt_trait!(LowerHex);
impl_fmt_trait!(LowerExp);
impl_fmt_trait!(UpperHex);
impl_fmt_trait!(UpperExp);
impl_fmt_trait!(Octal);
impl_fmt_trait!(Pointer);
impl_fmt_trait!(Binary);