indent_write/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3//! Simple indentation adapters for [`io::Write`][std::io::Write],
4//! [`fmt::Write`][std::fmt::Write], and [`Display`][std::fmt::Display]. Each
5//! adapter wraps a writer or writable object, and inserts an indentation at
6//! the front of each non-empty line.
7//!
8//! See [`fmt::IndentWriter`], [`io::IndentWriter`], and
9//! [`indentable::Indentable`] for examples.
10
11pub mod fmt;
12pub mod indentable;
13
14#[cfg(feature = "std")]
15pub mod io;
16
17trait Inspect<T> {
18    fn inspect(self, func: impl FnOnce(&T)) -> Self;
19}
20
21impl<T> Inspect<T> for Option<T> {
22    #[inline]
23    fn inspect(self, func: impl FnOnce(&T)) -> Self {
24        if let Some(ref value) = self {
25            func(value)
26        }
27
28        self
29    }
30}
31
32impl<T, E> Inspect<T> for Result<T, E> {
33    #[inline]
34    fn inspect(self, func: impl FnOnce(&T)) -> Self {
35        if let Ok(ref value) = self {
36            func(value)
37        }
38
39        self
40    }
41}